From 36585558a5b37b21924c749ae1c8470de7c1c04c Mon Sep 17 00:00:00 2001 From: Alexei Chetroi Date: Sat, 28 Dec 2019 15:41:55 -0500 Subject: [PATCH] Refactor ZHA channel logging (#30259) Add channel.id property -- id unique for this the device only. --- .../components/zha/core/channels/__init__.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/zha/core/channels/__init__.py b/homeassistant/components/zha/core/channels/__init__.py index 4013f05e0b6..5a337b2a537 100644 --- a/homeassistant/components/zha/core/channels/__init__.py +++ b/homeassistant/components/zha/core/channels/__init__.py @@ -89,19 +89,19 @@ class ZigbeeChannel(LogMixin): self._generic_id = f"channel_0x{cluster.cluster_id:04x}" self._cluster = cluster self._zha_device = device - self._unique_id = "{}:{}:0x{:04x}".format( - str(device.ieee), cluster.endpoint.endpoint_id, cluster.cluster_id - ) - # this keeps logs consistent with zigpy logging - self._log_id = "0x{:04x}:{}:0x{:04x}".format( - device.nwk, cluster.endpoint.endpoint_id, cluster.cluster_id - ) + self._id = f"{cluster.endpoint.endpoint_id}:0x{cluster.cluster_id:04x}" + self._unique_id = f"{str(device.ieee)}:{self._id}" self._report_config = CLUSTER_REPORT_CONFIGS.get( self._cluster.cluster_id, self.REPORT_CONFIG ) self._status = ChannelStatus.CREATED self._cluster.add_listener(self) + @property + def id(self) -> str: + """Return channel id unique for this device only.""" + return self._id + @property def generic_id(self): """Return the generic id for this channel.""" @@ -263,8 +263,8 @@ class ZigbeeChannel(LogMixin): def log(self, level, msg, *args): """Log a message.""" - msg = "[%s]: " + msg - args = (self._log_id,) + args + msg = "[%s:%s]: " + msg + args = (self.device.nwk, self._id,) + args _LOGGER.log(level, msg, *args) def __getattr__(self, name):