Skip to content

Commit

Permalink
Merge pull request #940 from onkelandy/knx
Browse files Browse the repository at this point in the history
knx plugin: improve logging for sending and polling
  • Loading branch information
onkelandy committed Jun 18, 2024
2 parents 9a71c89 + b45f6c2 commit 50db491
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions knx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ def __init__(self, smarthome):
self.date_ga = self.get_parameter_value('date_ga')
self._send_time_do = self.get_parameter_value('send_time')
self._bm_separatefile = False
self._bm_format = "BM': {1} set {2} to {3}"
self._bm_format = "BM: {1} set {2} to {3}"
self._bm_format_send = "BM: Sending value {3} for GA {2}"
self._bm_format_poll = "BM: Polling value for GA {2}"
self._startup_polling = {}

# following needed for statistics
Expand All @@ -110,6 +112,8 @@ def __init__(self, smarthome):
elif busmonitor.lower() == 'logger':
self._bm_separatefile = True
self._bm_format = "{0};{1};{2};{3}"
self._bm_format_send = "{0};{1};{2};{3}"
self._bm_format_poll = "{0};{1};{2}"
self._busmonitor = logging.getLogger("knx_busmonitor").info
self.logger.info(self.translate("Using busmonitor (L) = '{}'").format(busmonitor))
else:
Expand Down Expand Up @@ -241,6 +245,8 @@ def _poll(self, **kwargs):
item = 'unknown item'
if 'ga' in kwargs:
self.groupread(kwargs['ga'])
if self._log_own_packets is True and self.alive:
self._busmonitor(self._bm_format_poll.format(self.get_instance_name(), 'POLL', kwargs["ga"]))
else:
self.logger.warning(self.translate('problem polling {}, no known ga').format(item))

Expand Down Expand Up @@ -662,10 +668,6 @@ def parse_item(self, item):
randomwait = random.randrange(15)
next = self.shtime.now() + timedelta(seconds=poll_interval + randomwait)
self._startup_polling.update({item: {'ga': poll_ga, 'interval': poll_interval}})
'''
self._sh.scheduler.add(f'KNX poll {item}', self._poll,
value={ITEM: item, 'ga': poll_ga, 'interval': poll_interval}, next=next)
'''
else:
self.logger.warning("Ignoring knx_poll for item {}: We need two parameters, one for the GA and one for the polling interval.".format(item))
pass
Expand Down Expand Up @@ -737,14 +739,14 @@ def update_item(self, item, caller=None, source=None, dest=None):
for ga in self.get_iattr_value(item.conf, KNX_SEND):
_value = item()
if self._log_own_packets is True:
self._busmonitor(self._bm_format.format(self.get_instance_name(), 'SEND', ga, _value))
self._busmonitor(self._bm_format_send.format(self.get_instance_name(), 'SEND', ga, _value))
self.groupwrite(ga, _value, self.get_iattr_value(item.conf, KNX_DPT))
if self.has_iattr(item.conf, KNX_STATUS):
for ga in self.get_iattr_value(item.conf, KNX_STATUS): # send status update
if ga != dest:
_value = item()
if self._log_own_packets is True:
self._busmonitor(self._bm_format.format(self.get_instance_name(), 'STATUS', ga, _value))
self._busmonitor(self._bm_format_send.format(self.get_instance_name(), 'STATUS', ga, _value))
self.groupwrite(ga, _value, self.get_iattr_value(item.conf, KNX_DPT))


Expand Down

0 comments on commit 50db491

Please sign in to comment.