Skip to content

Commit

Permalink
uzsu plugin: replace caller UZSU Plugin by longname of plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
onkelandy committed Sep 14, 2023
1 parent 35b1ffd commit c26724b
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions uzsu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def __init__(self, smarthome):
self._webdata = {'sunCalculated': {}, 'items': {}}
self._update_count = {'todo': 0, 'done': 0}
self._itpl = {}
self._pluginname = self.get_fullname()
self.init_webinterface(WebInterface)
self.logger.info("Init with timezone {}".format(self._timezone))

Expand All @@ -145,7 +146,7 @@ def run(self):
self._items[item]['interpolation']['itemtype'] = self._add_type(item)
self._lastvalues[item] = None
self._webdata['items'][item.id()].update({'lastvalue': '-'})
self._update_item(item, 'UZSU Plugin', 'run')
self._update_item(item, self._pluginname, 'run')
cond1 = self._items[item].get('active') and self._items[item]['active'] is True
cond2 = self._items[item].get('list')
if cond1 and cond2:
Expand All @@ -158,7 +159,7 @@ def run(self):
# remove lastvalue dict entry, it is not used anymore
try:
self._items[item].pop('lastvalue')
self._update_item(item, 'UZSU Plugin', 'lastvalue removed')
self._update_item(item, self._pluginname, 'lastvalue removed')
self.logger.debug("Item '{}': removed lastvalue dict entry as it is deprecated.".format(item))
except Exception:
pass
Expand Down Expand Up @@ -199,7 +200,7 @@ def _update_all_suns(self, caller=None):
success = self._update_sun(item, caller="update_all_suns")
if success:
self.logger.debug('Updating sun info for item {}. Caller: {}'.format(item, caller))
self._update_item(item, 'UZSU Plugin', 'update_all_suns')
self._update_item(item, self._pluginname, 'update_all_suns')

def _update_sun(self, item, caller=None):
"""
Expand Down Expand Up @@ -239,12 +240,12 @@ def _update_suncalc(self, item, entry, entryindex, entryvalue):
if entry.get('calculated') and entryvalue is None:
self.logger.debug("No sunset/rise in time for current entry {}. Removing calculated value.".format(entry))
self._items[item]['list'][entryindex].pop('calculated')
self._update_item(item, 'UZSU Plugin', 'update_sun')
self._update_item(item, self._pluginname, 'update_sun')
elif update is True and not entry.get('calculated') == entryvalue:
self.logger.debug("Updated calculated time for item {} entry {} with value {}.".format(
item, self._items[item]['list'][entryindex], entryvalue))
self._items[item]['list'][entryindex]['calculated'] = entryvalue
self._update_item(item, 'UZSU Plugin', 'update_sun')
self._update_item(item, self._pluginname, 'update_sun')
elif entry.get('calculated'):
self.logger.debug("Sun calculation {} entry not updated for item {} with value {}".format(
entryvalue, item, entry.get('calculated')))
Expand Down Expand Up @@ -305,7 +306,7 @@ def _logics_activate(self, activevalue=None, item=None):
self._items[item] = item()
self._items[item]['active'] = activevalue
self.logger.info("Item {} is set via logic to: {}".format(item, activevalue))
self._update_item(item, 'UZSU Plugin', 'logic')
self._update_item(item, self._pluginname, 'logic')
return activevalue
if activevalue is None:
return self._items[item].get('active')
Expand All @@ -322,7 +323,7 @@ def _logics_interpolation(self, intpl_type=None, interval=None, backintime=None,
self._items[item]['interpolation']['initage'] = int(backintime)
self.logger.info("Item {} interpolation is set via logic to: type={}, interval={}, backintime={}".format(
item, intpl_type, abs(interval), backintime))
self._update_item(item, 'UZSU Plugin', 'logic')
self._update_item(item, self._pluginname, 'logic')
return self._items[item].get('interpolation')

def _logics_clear(self, clear=False, item=None):
Expand All @@ -335,7 +336,7 @@ def _logics_clear(self, clear=False, item=None):
self._items[item].clear()
self._items[item] = {'interpolation': {}, 'active': False}
self.logger.info("UZSU settings for item '{}' are cleared".format(item))
self._update_item(item, 'UZSU Plugin', 'clear')
self._update_item(item, self._pluginname, 'clear')
return True
else:
return False
Expand Down Expand Up @@ -429,7 +430,7 @@ def parse_item(self, item):
self._items[item]['list'][entry].pop('delayedExec', None)

self._webdata['items'].update({item.id(): {}})
self._update_item(item, 'UZSU Plugin', 'init')
self._update_item(item, self._pluginname, 'init')
self._planned.update({item: 'notinit'})
self._webdata['items'][item.id()].update({'planned': {'value': '-', 'time': '-'}})

Expand Down Expand Up @@ -478,7 +479,7 @@ def _check_rruleandplanned(self, item):
self.logger.warning("Error creating rrule: {}".format(err))
if count > 0:
self.logger.debug("Updated {} rrule entries for item: {}".format(count, item))
self._update_item(item, 'UZSU Plugin', 'create_rrule')
self._update_item(item, self._pluginname, 'create_rrule')
if _inactive >= len(self._items[item]['list']):
self._planned.update({item: None})
self._webdata['items'][item.id()].update({'planned': {'value': '-', 'time': '-'}})
Expand All @@ -492,7 +493,7 @@ def update_item(self, item, caller=None, source=None, dest=None):
:param source: if given it represents the source
:param dest: if given it represents the dest
"""
cond = (not caller == 'UZSU Plugin') or source == 'logic'
cond = (not caller == self._pluginname) or source == 'logic'
self.logger.debug('Update Item {}, Caller {}, Source {}, Dest {}. Will update: {}'.format(
item, caller, source, dest, cond))
if not source == 'create_rrule':
Expand Down Expand Up @@ -520,7 +521,7 @@ def update_item(self, item, caller=None, source=None, dest=None):
self._schedule(item, caller='dry_run')

if self._items[item] != self.itemsApi.return_item(str(item)) and cond:
self._update_item(item, 'UZSU Plugin', 'update')
self._update_item(item, self._pluginname, 'update')

def _update_item(self, item, caller="", comment=""):
success = self._get_sun4week(item, caller="_update_item")
Expand Down Expand Up @@ -628,7 +629,7 @@ def _schedule(self, item, caller=None):
if _interval < 0:
_interval = abs(int(_interval))
self._items[item]['interpolation']['interval'] = _interval
self._update_item(item, 'UZSU Plugin', 'intervalchange')
self._update_item(item, self._pluginname, 'intervalchange')
_interpolation = self._items[item]['interpolation'].get('type')
_interpolation = self._interpolation_type if not _interpolation else _interpolation
_initage = self._items[item]['interpolation'].get('initage')
Expand Down Expand Up @@ -663,7 +664,7 @@ def _schedule(self, item, caller=None):
self.logger.info("Looking if there was a value set after {} for item {}".format(
_timediff, item))
self._items[item]['interpolation']['initialized'] = True
self._update_item(item, 'UZSU Plugin', 'init')
self._update_item(item, self._pluginname, 'init')
if cond1 and not cond2 and cond3 and cond6:
self._set(item=item, value=_initvalue, caller=_caller)
self.logger.info("Updated item {} on startup with value {} from time {}".format(
Expand Down Expand Up @@ -709,7 +710,7 @@ def _schedule(self, item, caller=None):
" to not enough values set in the UZSU.".format(_value, item))
if _reset_interpolation is True:
self._items[item]['interpolation']['type'] = 'none'
self._update_item(item, 'UZSU Plugin', 'reset_interpolation')
self._update_item(item, self._pluginname, 'reset_interpolation')
if _caller != "dry_run":
self.logger.debug("will add scheduler named uzsu_{} with datetime {} and tzinfo {}"
" and value {}".format(item.property.path, _next, _next.tzinfo, _value))
Expand All @@ -719,7 +720,7 @@ def _schedule(self, item, caller=None):
self.scheduler_add('{}'.format(item.property.path), self._set,
value={'item': item, 'value': _value, 'caller': 'Scheduler'}, next=_next)
if self._update_count.get('done') == self._update_count.get('todo'):
self.scheduler_trigger('uzsu_sunupdate', by='UZSU Plugin')
self.scheduler_trigger('uzsu_sunupdate', by=self._pluginname)
self._update_count = {'done': 0, 'todo': 0}
elif self._items[item].get('active') is True and self._items[item].get('list'):
self.logger.warning("item '{}' is active but has no active entries.".format(item))
Expand All @@ -734,7 +735,7 @@ def _set(self, item=None, value=None, caller=None):
:param caller: if given it represents the callers name
"""
_uzsuitem, _itemvalue = self._get_dependant(item)
_uzsuitem(value, 'UZSU Plugin', 'set')
_uzsuitem(value, self._pluginname, 'set')
self._webdata['items'][item.id()].update({'depend': {'item': _uzsuitem.id(), 'value': str(_itemvalue)}})
if not caller or caller == "Scheduler":
self._schedule(item, caller='set')
Expand Down

0 comments on commit c26724b

Please sign in to comment.