Closed chakjer closed 1 year ago
I am unsure if it's an issue with HABApp or an issue with one of your rules.
Could you provide the rule snippets where you interact with var1
and var2
?
I found my error, i pointed to variable self.var not self.var.value. It is really strange because in version <1.0.x it worked well.
Yes that was introduced with this update. I was unaware this was a breaking change. Could you describe what you are doing (e.g. code snippet). If it makes sense I'll add it again ...
From my point it was a good change, now code is more clearly. It is a function to store power consumption for shelly devices ''' class powerRules(HABApp.Rule):
def __init__(self):
super().__init__()
self.varTotal = NumberItem.get_item('powerTotal')
self.var= NumberItem.get_item('powerCurr')
self.var1 = NumberItem.get_item('powerPrev')
self.var.listen_event(self.power_update,ItemStateChangedEventFilter())
def power_update(self, event: ItemStateChangedEvent):
if not isinstance(self.var1,NumberItem) or (self.var1.value == None):
self.var1.value = self.var.value
if not isinstance(self.varSum,NumberItem) or (self.varSum.value == None):
self.varTotal.value = 0
if self.var.value - self.var1.value > 0 :
self.varTotal.value += self.var.value-self.var1.value
self.oh.post_update('powerTotal',self.varTotal.value)
self.oh.post_update('powerPrev',self.var.value)
'''
Just a hint:
The isinstance
is not necessary because get_item
will throw an error if the type is not correct.
If you want to handle None values you should use get_value
:
pwr_curr = self.var.get_value(0)
I however prefer to just start a task that initializes the values on rule startup:
def __init__(self)
....
self.run.soon(self.initialize)
def initialize(self):
if self.var1.value is None:
self.var1.oh_post_update(0)
I have some issue with timestamp for NumberItem after upgrade version to 1.0.4 Do i miss something in configuration?