mirror of https://github.com/arendst/Tasmota.git
HASPmota `p<x>b<y>.delete` to delete an object (#20735)
This commit is contained in:
parent
f05cb6d50b
commit
b91f93062a
|
@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
## [13.4.0.1]
|
## [13.4.0.1]
|
||||||
### Added
|
### Added
|
||||||
|
- HASPmota `p<x>b<y>.delete` to delete an object
|
||||||
|
|
||||||
### Breaking Changed
|
### Breaking Changed
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -358,6 +358,22 @@ class lvh_obj
|
||||||
end
|
end
|
||||||
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
|
# Mapping of synthetic attributes
|
||||||
# - text
|
# - text
|
||||||
|
@ -841,7 +857,7 @@ class lvh_obj
|
||||||
end
|
end
|
||||||
|
|
||||||
# fallback to exception if attribute unknown or not a function
|
# fallback to exception if attribute unknown or not a function
|
||||||
raise "value_error", "unknown attribute " + str(k)
|
return module("undefined")
|
||||||
end
|
end
|
||||||
|
|
||||||
#- ------------------------------------------------------------#
|
#- ------------------------------------------------------------#
|
||||||
|
@ -943,11 +959,14 @@ class lvh_obj
|
||||||
# `text_rule_format`: format used by `format()`
|
# `text_rule_format`: format used by `format()`
|
||||||
# Ex: `%.1f °C`
|
# Ex: `%.1f °C`
|
||||||
#====================================================================
|
#====================================================================
|
||||||
def set_val_rule(t)
|
def remove_val_rule()
|
||||||
# remove previous rule if any
|
|
||||||
if self._val_rule != nil
|
if self._val_rule != nil
|
||||||
tasmota.remove_rule(self._val_rule, self)
|
tasmota.remove_rule(self._val_rule, self)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
def set_val_rule(t)
|
||||||
|
# remove previous rule if any
|
||||||
|
self.remove_val_rule()
|
||||||
|
|
||||||
self._val_rule = str(t)
|
self._val_rule = str(t)
|
||||||
tasmota.add_rule(self._val_rule, / val -> self.val_rule_matched(val), self)
|
tasmota.add_rule(self._val_rule, / val -> self.val_rule_matched(val), self)
|
||||||
|
@ -956,11 +975,14 @@ class lvh_obj
|
||||||
return self._val_rule
|
return self._val_rule
|
||||||
end
|
end
|
||||||
# text_rule
|
# text_rule
|
||||||
def set_text_rule(t)
|
def remove_text_rule()
|
||||||
# remove previous rule if any
|
|
||||||
if self._text_rule != nil
|
if self._text_rule != nil
|
||||||
tasmota.remove_rule(self._text_rule, self)
|
tasmota.remove_rule(self._text_rule, self)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
def set_text_rule(t)
|
||||||
|
# remove previous rule if any
|
||||||
|
self.remove_text_rule()
|
||||||
|
|
||||||
self._text_rule = str(t)
|
self._text_rule = str(t)
|
||||||
tasmota.add_rule(self._text_rule, / val -> self.text_rule_matched(val), self)
|
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
|
# add an object to this page
|
||||||
#====================================================================
|
#====================================================================
|
||||||
def set_obj(id, o)
|
def get_obj(obj_id)
|
||||||
self._obj_id[id] = o
|
return self._obj_id.find(obj_id)
|
||||||
end
|
end
|
||||||
def get_obj(id)
|
def add_obj(obj_id, obj_lvh)
|
||||||
return self._obj_id.find(id)
|
# 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
|
||||||
end
|
end
|
||||||
|
|
||||||
#====================================================================
|
#====================================================================
|
||||||
|
@ -1622,16 +1660,6 @@ class HASPmota
|
||||||
if type(v) != 'int' lv.version = 8 end
|
if type(v) != 'int' lv.version = 8 end
|
||||||
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
|
# init
|
||||||
#
|
#
|
||||||
|
@ -2017,12 +2045,7 @@ class HASPmota
|
||||||
obj_lvh = obj_class(parent_lvgl, page, jline, lv_instance)
|
obj_lvh = obj_class(parent_lvgl, page, jline, lv_instance)
|
||||||
|
|
||||||
# add object to page object
|
# add object to page object
|
||||||
lvh_page_cur.set_obj(obj_id, obj_lvh)
|
lvh_page_cur.add_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
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if func_compiled != nil
|
if func_compiled != nil
|
||||||
|
|
Loading…
Reference in New Issue