diff --git a/apps/qolsysgw/mqtt/updater.py b/apps/qolsysgw/mqtt/updater.py index 5385ae7..cedc5d9 100644 --- a/apps/qolsysgw/mqtt/updater.py +++ b/apps/qolsysgw/mqtt/updater.py @@ -147,6 +147,27 @@ def payload_available(self): def payload_unavailable(self): return 'offline' + @property + def device_payload(self): + payload = { + 'name': self._cfg.panel_device_name, + 'identifiers': [ + self._cfg.panel_unique_id, + ], + 'manufacturer': 'Qolsys', + 'model': 'IQ Panel 2+', + } + + # If we are able to resolve the mac address, this will allow to + # link the device to other related elements in home assistant + mac = self._cfg.panel_mac or get_mac_from_host(self._cfg.panel_host) + if mac: + payload['connections'] = [ + ['mac', mac], + ] + + return payload + @property def configure_availability(self): availability = [ @@ -249,22 +270,7 @@ def configure_payload(self, **kwargs): } payload['unique_id'] = f"{self._cfg.panel_unique_id}_last_error" - payload['device'] = { - 'name': self._cfg.panel_device_name, - 'identifiers': [ - self._cfg.panel_unique_id, - ], - 'manufacturer': 'Qolsys', - 'model': 'IQ Panel 2+', - } - - # If we are able to resolve the mac address, this will allow to - # link the device to other related elements in home assistant - mac = self._cfg.panel_mac or get_mac_from_host(self._cfg.panel_host) - if mac: - payload['device']['connections'] = [ - ['mac', mac], - ] + payload['device'] = self.device_payload return payload @@ -373,22 +379,7 @@ def configure_payload(self, **kwargs): # together; this will also allow to interact with the partition in # the UI, change it's name, assign it to areas, etc. payload['unique_id'] = f"{self._cfg.panel_unique_id}_p{self._partition.id}" - payload['device'] = { - 'name': self._cfg.panel_device_name, - 'identifiers': [ - self._cfg.panel_unique_id, - ], - 'manufacturer': 'Qolsys', - 'model': 'IQ Panel 2+', - } - - # If we are able to resolve the mac address, this will allow to - # link the device to other related elements in home assistant - mac = self._cfg.panel_mac or get_mac_from_host(self._cfg.panel_host) - if mac: - payload['device']['connections'] = [ - ['mac', mac], - ] + payload['device'] = self.device_payload if self._cfg.default_trigger_command: payload['payload_trigger'] = self._cfg.default_trigger_command @@ -497,22 +488,7 @@ def configure_payload(self, partition: QolsysPartition, **kwargs): payload['unique_id'] = f"{self._cfg.panel_unique_id}_"\ f"p{self._sensor.partition_id}"\ f"z{self._sensor.zone_id}" - payload['device'] = { - 'name': self._cfg.panel_device_name, - 'identifiers': [ - self._cfg.panel_unique_id, - ], - 'manufacturer': 'Qolsys', - 'model': 'IQ Panel 2+', - } - - # If we are able to resolve the mac address, this will allow to - # link the device to other related elements in home assistant - mac = self._cfg.panel_mac or get_mac_from_host(self._cfg.panel_host) - if mac: - payload['device']['connections'] = [ - ['mac', mac], - ] + payload['device'] = self.device_payload return payload