Skip to content

Commit

Permalink
lib.item: adjust for calculation autotimer value at call time
Browse files Browse the repository at this point in the history
  • Loading branch information
Morg42 committed Feb 25, 2025
1 parent 05f4882 commit cac9cef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
13 changes: 6 additions & 7 deletions lib/item/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -2677,20 +2677,19 @@ def check_external_change(entry_type, entry_value):
# debug
logger.debug(f'autotimer: {self._autotimer_time} / {self._autotimer_value}')
_time = self.get_attr_time('autotimer')
_value = value
if _time is None:
logger.warning(f'evaluating autotimer time {self._autotimer_time} returned None, ignoring')
elif type(_time) is not int:
logger.warning(f"autotimer time {self._autotimer_time} didn't result in int, but in {_time}, type {type(_time)}")
else:
if self._autotimer_value is None:
_value = self._value
else:
_value = self.get_attr_value('autotimer')
_value = self._autotimer_value

# debug
logger.notice(f"Item {self._path} __update: _time={_time}, _value={_value}")
logger.notice(f"Item {self._path} __update: _time={_time}, _value={_value}")

next = self.shtime.now() + datetime.timedelta(seconds=_time)
self._sh.scheduler.add(self._itemname_prefix+self.id() + '-Timer', self.__call__, value={'value': _value, 'caller': 'Autotimer'}, next=next)
next = self.shtime.now() + datetime.timedelta(seconds=_time)
self._sh.scheduler.add(self._itemname_prefix + self.id() + '-Timer', self, value={'value': _value, 'caller': 'Autotimer'}, next=next)

def add_logic_trigger(self, logic):
"""
Expand Down
11 changes: 9 additions & 2 deletions lib/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,8 @@ def _task(self, name, obj, by, source, dest, value):
threading.current_thread().name = name
#logger = logging.getLogger('_task.' + name)

# debug
logger.warning(f'task {obj} ({obj.__class__.__name__}) with {value} by {by} source {source}')
if obj.__class__.__name__ == 'Logic':
self._execute_logic_task(obj, by, source, dest, value)

Expand All @@ -780,13 +782,18 @@ def _task(self, name, obj, by, source, dest, value):
scheduler_source = str(source.get('source', ''))
if scheduler_source != '':
scheduler_source = ':' + scheduler_source + ':' + str(source.get('details', ''))
src = 'cycle'
if isinstance(value, dict) and value.get('caller') == 'Autotimer':
src = 'autotimer'
if value is None:
# re-set current item value. needs enforce_updates to work properly
value = obj()
else:
# get current (static or evaluated) value from item itself
value = obj.get_attr_value('cycle')
obj(value, caller=("Scheduler" + scheduler_source))
value = obj.get_attr_value(src)
# debug
logger.debug(f'item {obj}: src = {src}, value = {value}')
obj(value, caller="Autotimer")
except Exception as e:
tasks_logger.exception(f"Item {name} exception: {e}")

Expand Down

0 comments on commit cac9cef

Please sign in to comment.