From 16c24d799de81852df9c28554ebf4469baad98fc Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 30 Nov 2022 01:02:25 +0100 Subject: [PATCH] Removed custom formatting for child zigbee/zwave entity names The parent->child relationship is now modelled on the database itself, so we no longer need value names specifically formatted as `[DeviceName] ValueName` - the UI will take care of it. --- platypush/plugins/zigbee/mqtt/__init__.py | 25 +++++------------------ platypush/plugins/zwave/mqtt/__init__.py | 19 ++++++----------- 2 files changed, 11 insertions(+), 33 deletions(-) diff --git a/platypush/plugins/zigbee/mqtt/__init__.py b/platypush/plugins/zigbee/mqtt/__init__.py index c64db5545..3e798594b 100644 --- a/platypush/plugins/zigbee/mqtt/__init__.py +++ b/platypush/plugins/zigbee/mqtt/__init__.py @@ -215,7 +215,7 @@ class ZigbeeMqttPlugin(MqttPlugin): # lgtm [py/missing-call-to-init] dev_entities.append( Light( id=f'{dev["ieee_address"]}:light', - name=dev.get('friendly_name'), + name='Light', on=dev.get('state', {}).get('state') == switch_info.get('value_on'), brightness_min=light_info.get('brightness_min'), @@ -264,7 +264,7 @@ class ZigbeeMqttPlugin(MqttPlugin): # lgtm [py/missing-call-to-init] dev_entities.append( Switch( id=f'{dev["ieee_address"]}:switch', - name=dev.get('friendly_name'), + name='Switch', state=dev.get('state', {}).get('state') == switch_info['value_on'], description=dev_def.get("description"), @@ -1566,12 +1566,7 @@ class ZigbeeMqttPlugin(MqttPlugin): # lgtm [py/missing-call-to-init] entity_type = None sensor_args = { 'id': f'{device_info["ieee_address"]}:{exposed["property"]}', - 'name': ( - device_info.get('friendly_name', '[Unnamed device]') - + ' [' - + exposed.get('description', '') - + ']' - ), + 'name': exposed.get('description', ''), 'value': device_info.get('state', {}).get(exposed['property']), 'description': exposed.get('description'), 'is_read_only': cls._is_read_only(exposed), @@ -1626,12 +1621,7 @@ class ZigbeeMqttPlugin(MqttPlugin): # lgtm [py/missing-call-to-init] return [ Dimmer( id=f'{device_info["ieee_address"]}:{exposed["property"]}', - name=( - device_info.get('friendly_name', '[Unnamed device]') - + ' [' - + exposed.get('description', '') - + ']' - ), + name=exposed.get('description', ''), value=device_info.get('state', {}).get(exposed['property']), min=exposed.get('value_min'), max=exposed.get('value_max'), @@ -1656,12 +1646,7 @@ class ZigbeeMqttPlugin(MqttPlugin): # lgtm [py/missing-call-to-init] return [ EnumSwitch( id=f'{device_info["ieee_address"]}:{exposed["property"]}', - name=( - device_info.get('friendly_name', '[Unnamed device]') - + ' [' - + exposed.get('description', '') - + ']' - ), + name=exposed.get('description', ''), value=device_info.get(exposed['property']), values=exposed.get('values', []), description=exposed.get('description'), diff --git a/platypush/plugins/zwave/mqtt/__init__.py b/platypush/plugins/zwave/mqtt/__init__.py index 068bfd643..c8f5656d6 100644 --- a/platypush/plugins/zwave/mqtt/__init__.py +++ b/platypush/plugins/zwave/mqtt/__init__.py @@ -600,31 +600,21 @@ class ZwaveMqttPlugin(MqttPlugin, ZwaveBasePlugin): value = { **value, 'id': current_value_id, - 'label': 'Current Value', + 'label': 'Value', 'is_read_only': False, 'is_write_only': False, } args = { 'id': value['id'], - 'name': '{node_name} [{value_name}]'.format( - node_name=self._nodes_cache['by_id'][value['node_id']].get( - 'name', f'[Node {value["node_id"]}]' - ), - value_name=value.get('label'), - ), + 'name': value.get('label'), 'description': value.get('help'), 'is_read_only': value.get('is_read_only'), 'is_write_only': value.get('is_write_only'), - 'data': { - 'label': value.get('label'), - 'node_id': value.get('node_id'), - }, } if value.get('last_update'): args['updated_at'] = value['last_update'] - return args def transform_entities(self, values: Iterable[Mapping]): @@ -675,6 +665,9 @@ class ZwaveMqttPlugin(MqttPlugin, ZwaveBasePlugin): entities_by_id: Dict[str, Entity] = {str(e.id): e for e in entities} for value in values: + if not (value and value.get('id')): + continue + entity = entities_by_id.get(value['id']) if not entity: continue @@ -733,7 +726,7 @@ class ZwaveMqttPlugin(MqttPlugin, ZwaveBasePlugin): ) value['id'] = value['value_id'] = value['id_on_network'] = value_id value['is_read_only'] = value['is_write_only'] = False - value['label'] = 'Current Value' + value['label'] = 'Value' value['property_id'] = 'currentValue' value['last_update'] = ( max(