HASPmota `p<x>b<y>.delete` to delete an object (#20735)

This commit is contained in:
s-hadinger 2024-02-15 23:16:12 +01:00 committed by GitHub
parent f05cb6d50b
commit b91f93062a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4297 additions and 4120 deletions

View File

@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
## [13.4.0.1]
### Added
- HASPmota `p<x>b<y>.delete` to delete an object
### Breaking Changed

File diff suppressed because it is too large Load Diff

View File

@ -358,6 +358,22 @@ class lvh_obj
end
end
#====================================================================
# `delete` special attribute used to delete the object
#====================================================================
def set_delete(v)
raise "type_error", "you cannot assign to 'delete'"
end
def get_delete()
# remove any rule
self.remove_val_rule()
self.remove_text_rule()
if (self._lv_label) self._lv_label.del() self._lv_label = nil end
if (self._lv_obj) self._lv_obj.del() self._lv_obj = nil end
# remove from page
self._page.remove_obj(self.id)
end
#====================================================================
# Mapping of synthetic attributes
# - text
@ -841,7 +857,7 @@ class lvh_obj
end
# fallback to exception if attribute unknown or not a function
raise "value_error", "unknown attribute " + str(k)
return module("undefined")
end
#- ------------------------------------------------------------#
@ -943,11 +959,14 @@ class lvh_obj
# `text_rule_format`: format used by `format()`
# Ex: `%.1f °C`
#====================================================================
def set_val_rule(t)
# remove previous rule if any
def remove_val_rule()
if self._val_rule != nil
tasmota.remove_rule(self._val_rule, self)
end
end
def set_val_rule(t)
# remove previous rule if any
self.remove_val_rule()
self._val_rule = str(t)
tasmota.add_rule(self._val_rule, / val -> self.val_rule_matched(val), self)
@ -956,11 +975,14 @@ class lvh_obj
return self._val_rule
end
# text_rule
def set_text_rule(t)
# remove previous rule if any
def remove_text_rule()
if self._text_rule != nil
tasmota.remove_rule(self._text_rule, self)
end
end
def set_text_rule(t)
# remove previous rule if any
self.remove_text_rule()
self._text_rule = str(t)
tasmota.add_rule(self._text_rule, / val -> self.text_rule_matched(val), self)
@ -1502,11 +1524,27 @@ class lvh_page
#====================================================================
# add an object to this page
#====================================================================
def set_obj(id, o)
self._obj_id[id] = o
def get_obj(obj_id)
return self._obj_id.find(obj_id)
end
def add_obj(obj_id, obj_lvh)
# add object to page object
self._obj_id[obj_id] = obj_lvh
# create a global variable for this object of form p<page>b<id>, ex p1b2
var glob_name = format("p%ib%i", obj_lvh._page.id(), obj_id)
global.(glob_name) = obj_lvh
end
def remove_obj(obj_id)
# remove object from page object
var obj_lvh = self._obj_id.find(obj_id)
self._obj_id.remove(obj_id)
# set the global variable to `nil`
if obj_lvh
var glob_name = format("p%ib%i", obj_lvh._page.id(), obj_id)
global.(glob_name) = nil
end
def get_obj(id)
return self._obj_id.find(id)
end
#====================================================================
@ -1622,16 +1660,6 @@ class HASPmota
if type(v) != 'int' lv.version = 8 end
end
def deinit()
# remove previous rule if any
if self._val_rule != nil
tasmota.remove_rule(self._val_rule, self)
end
if self._text_rule != nil
tasmota.remove_rule(self._text_rule, self)
end
end
#====================================================================
# init
#
@ -2017,12 +2045,7 @@ class HASPmota
obj_lvh = obj_class(parent_lvgl, page, jline, lv_instance)
# add object to page object
lvh_page_cur.set_obj(obj_id, obj_lvh)
# create a global variable for this object of form p<page>b<id>, ex p1b2
var glob_name = format("p%ib%i", lvh_page_cur.id(), obj_id)
global.(glob_name) = obj_lvh
lvh_page_cur.add_obj(obj_id, obj_lvh)
end
if func_compiled != nil