From 5595ef07838ed46f148c67b7bd885ec26ee5d3f6 Mon Sep 17 00:00:00 2001 From: Alexei Chetroi Date: Fri, 12 Jun 2020 06:08:11 -0400 Subject: [PATCH] Drop ZHA sensor for Analog/Multistate input clusters (#36696) --- .../components/zha/core/channels/__init__.py | 5 +- homeassistant/components/zha/sensor.py | 21 --- tests/components/zha/zha_devices_list.py | 122 +----------------- 3 files changed, 9 insertions(+), 139 deletions(-) diff --git a/homeassistant/components/zha/core/channels/__init__.py b/homeassistant/components/zha/core/channels/__init__.py index 18eb2a6c1cc6..f0ef6f382c49 100644 --- a/homeassistant/components/zha/core/channels/__init__.py +++ b/homeassistant/components/zha/core/channels/__init__.py @@ -3,6 +3,8 @@ import asyncio import logging from typing import Any, Dict, List, Optional, Tuple, Union +import zigpy.zcl.clusters.closures + from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_send @@ -280,9 +282,10 @@ class ChannelPool: # incorrectly. if ( hasattr(cluster, "ep_attribute") + and cluster_id == zigpy.zcl.clusters.closures.DoorLock.cluster_id and cluster.ep_attribute == "multistate_input" ): - channel_class = base.ZigbeeChannel + channel_class = general.MultistateInput # end of ugly hack channel = channel_class(cluster, self) if channel.name == const.CHANNEL_POWER_CONFIGURATION: diff --git a/homeassistant/components/zha/sensor.py b/homeassistant/components/zha/sensor.py index 4544780b4f86..86969c5fe966 100644 --- a/homeassistant/components/zha/sensor.py +++ b/homeassistant/components/zha/sensor.py @@ -25,11 +25,9 @@ from homeassistant.util.temperature import fahrenheit_to_celsius from .core import discovery from .core.const import ( - CHANNEL_ANALOG_INPUT, CHANNEL_ELECTRICAL_MEASUREMENT, CHANNEL_HUMIDITY, CHANNEL_ILLUMINANCE, - CHANNEL_MULTISTATE_INPUT, CHANNEL_POWER_CONFIGURATION, CHANNEL_PRESSURE, CHANNEL_SMARTENERGY_METERING, @@ -153,13 +151,6 @@ class Sensor(ZhaEntity): return round(float(value * self._multiplier) / self._divisor) -@STRICT_MATCH(channel_names=CHANNEL_ANALOG_INPUT) -class AnalogInput(Sensor): - """Sensor that displays analog input values.""" - - SENSOR_ATTR = "present_value" - - @STRICT_MATCH(channel_names=CHANNEL_POWER_CONFIGURATION) class Battery(Sensor): """Battery sensor of power configuration cluster.""" @@ -220,18 +211,6 @@ class ElectricalMeasurement(Sensor): return round(value) -@STRICT_MATCH(channel_names=CHANNEL_MULTISTATE_INPUT) -class Text(Sensor): - """Sensor that displays string values.""" - - _device_class = None - _unit = None - - def formatter(self, value) -> str: - """Return string value.""" - return value - - @STRICT_MATCH(generic_ids=CHANNEL_ST_HUMIDITY_CLUSTER) @STRICT_MATCH(channel_names=CHANNEL_HUMIDITY) class Humidity(Sensor): diff --git a/tests/components/zha/zha_devices_list.py b/tests/components/zha/zha_devices_list.py index d4ea1377d978..6de4bd79a729 100644 --- a/tests/components/zha/zha_devices_list.py +++ b/tests/components/zha/zha_devices_list.py @@ -1372,8 +1372,6 @@ DEVICES = [ }, }, "entities": [ - "sensor.lumi_lumi_plug_maus01_77665544_analog_input", - "sensor.lumi_lumi_plug_maus01_77665544_analog_input_2", "sensor.lumi_lumi_plug_maus01_77665544_electrical_measurement", "switch.lumi_lumi_plug_maus01_77665544_on_off", ], @@ -1388,16 +1386,6 @@ DEVICES = [ "entity_class": "ElectricalMeasurement", "entity_id": "sensor.lumi_lumi_plug_maus01_77665544_electrical_measurement", }, - ("sensor", "00:11:22:33:44:55:66:77-2-12"): { - "channels": ["analog_input"], - "entity_class": "AnalogInput", - "entity_id": "sensor.lumi_lumi_plug_maus01_77665544_analog_input", - }, - ("sensor", "00:11:22:33:44:55:66:77-3-12"): { - "channels": ["analog_input"], - "entity_class": "AnalogInput", - "entity_id": "sensor.lumi_lumi_plug_maus01_77665544_analog_input_2", - }, }, "event_channels": ["1:0x0019"], "manufacturer": "LUMI", @@ -1426,7 +1414,6 @@ DEVICES = [ "entities": [ "light.lumi_lumi_relay_c2acn01_77665544_on_off", "light.lumi_lumi_relay_c2acn01_77665544_on_off_2", - "sensor.lumi_lumi_relay_c2acn01_77665544_analog_input", "sensor.lumi_lumi_relay_c2acn01_77665544_electrical_measurement", ], "entity_map": { @@ -1435,11 +1422,6 @@ DEVICES = [ "entity_class": "Light", "entity_id": "light.lumi_lumi_relay_c2acn01_77665544_on_off", }, - ("sensor", "00:11:22:33:44:55:66:77-1-12"): { - "channels": ["analog_input"], - "entity_class": "AnalogInput", - "entity_id": "sensor.lumi_lumi_relay_c2acn01_77665544_analog_input", - }, ("sensor", "00:11:22:33:44:55:66:77-1-2820"): { "channels": ["electrical_measurement"], "entity_class": "ElectricalMeasurement", @@ -1482,33 +1464,13 @@ DEVICES = [ "profile_id": 260, }, }, - "entities": [ - "sensor.lumi_lumi_remote_b186acn01_77665544_multistate_input", - "sensor.lumi_lumi_remote_b186acn01_77665544_multistate_input_2", - "sensor.lumi_lumi_remote_b186acn01_77665544_multistate_input_3", - "sensor.lumi_lumi_remote_b186acn01_77665544_power", - ], + "entities": ["sensor.lumi_lumi_remote_b186acn01_77665544_power"], "entity_map": { ("sensor", "00:11:22:33:44:55:66:77-1-1"): { "channels": ["power"], "entity_class": "Battery", "entity_id": "sensor.lumi_lumi_remote_b186acn01_77665544_power", }, - ("sensor", "00:11:22:33:44:55:66:77-1-18"): { - "channels": ["multistate_input"], - "entity_class": "Text", - "entity_id": "sensor.lumi_lumi_remote_b186acn01_77665544_multistate_input_2", - }, - ("sensor", "00:11:22:33:44:55:66:77-2-18"): { - "channels": ["multistate_input"], - "entity_class": "Text", - "entity_id": "sensor.lumi_lumi_remote_b186acn01_77665544_multistate_input_3", - }, - ("sensor", "00:11:22:33:44:55:66:77-3-18"): { - "channels": ["multistate_input"], - "entity_class": "Text", - "entity_id": "sensor.lumi_lumi_remote_b186acn01_77665544_multistate_input", - }, }, "event_channels": ["1:0x0005", "1:0x0019", "2:0x0005", "3:0x0005"], "manufacturer": "LUMI", @@ -1541,33 +1503,13 @@ DEVICES = [ "profile_id": 260, }, }, - "entities": [ - "sensor.lumi_lumi_remote_b286acn01_77665544_multistate_input", - "sensor.lumi_lumi_remote_b286acn01_77665544_multistate_input_2", - "sensor.lumi_lumi_remote_b286acn01_77665544_multistate_input_3", - "sensor.lumi_lumi_remote_b286acn01_77665544_power", - ], + "entities": ["sensor.lumi_lumi_remote_b286acn01_77665544_power"], "entity_map": { ("sensor", "00:11:22:33:44:55:66:77-1-1"): { "channels": ["power"], "entity_class": "Battery", "entity_id": "sensor.lumi_lumi_remote_b286acn01_77665544_power", }, - ("sensor", "00:11:22:33:44:55:66:77-1-18"): { - "channels": ["multistate_input"], - "entity_class": "Text", - "entity_id": "sensor.lumi_lumi_remote_b286acn01_77665544_multistate_input_3", - }, - ("sensor", "00:11:22:33:44:55:66:77-2-18"): { - "channels": ["multistate_input"], - "entity_class": "Text", - "entity_id": "sensor.lumi_lumi_remote_b286acn01_77665544_multistate_input_2", - }, - ("sensor", "00:11:22:33:44:55:66:77-3-18"): { - "channels": ["multistate_input"], - "entity_class": "Text", - "entity_id": "sensor.lumi_lumi_remote_b286acn01_77665544_multistate_input", - }, }, "event_channels": ["1:0x0005", "1:0x0019", "2:0x0005", "3:0x0005"], "manufacturer": "LUMI", @@ -1897,33 +1839,13 @@ DEVICES = [ "profile_id": 260, }, }, - "entities": [ - "sensor.lumi_lumi_sensor_86sw1_77665544_multistate_input", - "sensor.lumi_lumi_sensor_86sw1_77665544_multistate_input_2", - "sensor.lumi_lumi_sensor_86sw1_77665544_multistate_input_3", - "sensor.lumi_lumi_sensor_86sw1_77665544_power", - ], + "entities": ["sensor.lumi_lumi_sensor_86sw1_77665544_power"], "entity_map": { ("sensor", "00:11:22:33:44:55:66:77-1-1"): { "channels": ["power"], "entity_class": "Battery", "entity_id": "sensor.lumi_lumi_sensor_86sw1_77665544_power", }, - ("sensor", "00:11:22:33:44:55:66:77-1-18"): { - "channels": ["multistate_input"], - "entity_class": "Text", - "entity_id": "sensor.lumi_lumi_sensor_86sw1_77665544_multistate_input_3", - }, - ("sensor", "00:11:22:33:44:55:66:77-2-18"): { - "channels": ["multistate_input"], - "entity_class": "Text", - "entity_id": "sensor.lumi_lumi_sensor_86sw1_77665544_multistate_input_2", - }, - ("sensor", "00:11:22:33:44:55:66:77-3-18"): { - "channels": ["multistate_input"], - "entity_class": "Text", - "entity_id": "sensor.lumi_lumi_sensor_86sw1_77665544_multistate_input", - }, }, "event_channels": ["1:0x0005", "1:0x0019", "2:0x0005", "3:0x0005"], "manufacturer": "LUMI", @@ -1956,27 +1878,13 @@ DEVICES = [ "profile_id": 260, }, }, - "entities": [ - "sensor.lumi_lumi_sensor_cube_aqgl01_77665544_analog_input", - "sensor.lumi_lumi_sensor_cube_aqgl01_77665544_multistate_input", - "sensor.lumi_lumi_sensor_cube_aqgl01_77665544_power", - ], + "entities": ["sensor.lumi_lumi_sensor_cube_aqgl01_77665544_power"], "entity_map": { ("sensor", "00:11:22:33:44:55:66:77-1-1"): { "channels": ["power"], "entity_class": "Battery", "entity_id": "sensor.lumi_lumi_sensor_cube_aqgl01_77665544_power", }, - ("sensor", "00:11:22:33:44:55:66:77-2-18"): { - "channels": ["multistate_input"], - "entity_class": "Text", - "entity_id": "sensor.lumi_lumi_sensor_cube_aqgl01_77665544_multistate_input", - }, - ("sensor", "00:11:22:33:44:55:66:77-3-12"): { - "channels": ["analog_input"], - "entity_class": "AnalogInput", - "entity_id": "sensor.lumi_lumi_sensor_cube_aqgl01_77665544_analog_input", - }, }, "event_channels": ["1:0x0005", "1:0x0019", "2:0x0005", "3:0x0005"], "manufacturer": "LUMI", @@ -2161,8 +2069,6 @@ DEVICES = [ }, "entities": [ "binary_sensor.lumi_lumi_sensor_smoke_77665544_ias_zone", - "sensor.lumi_lumi_sensor_smoke_77665544_analog_input", - "sensor.lumi_lumi_sensor_smoke_77665544_multistate_input", "sensor.lumi_lumi_sensor_smoke_77665544_power", ], "entity_map": { @@ -2171,16 +2077,6 @@ DEVICES = [ "entity_class": "Battery", "entity_id": "sensor.lumi_lumi_sensor_smoke_77665544_power", }, - ("sensor", "00:11:22:33:44:55:66:77-1-12"): { - "channels": ["analog_input"], - "entity_class": "AnalogInput", - "entity_id": "sensor.lumi_lumi_sensor_smoke_77665544_analog_input", - }, - ("sensor", "00:11:22:33:44:55:66:77-1-18"): { - "channels": ["multistate_input"], - "entity_class": "Text", - "entity_id": "sensor.lumi_lumi_sensor_smoke_77665544_multistate_input", - }, ("binary_sensor", "00:11:22:33:44:55:66:77-1-1280"): { "channels": ["ias_zone"], "entity_class": "IASZone", @@ -2254,21 +2150,13 @@ DEVICES = [ "profile_id": 260, } }, - "entities": [ - "sensor.lumi_lumi_sensor_switch_aq3_77665544_multistate_input", - "sensor.lumi_lumi_sensor_switch_aq3_77665544_power", - ], + "entities": ["sensor.lumi_lumi_sensor_switch_aq3_77665544_power"], "entity_map": { ("sensor", "00:11:22:33:44:55:66:77-1-1"): { "channels": ["power"], "entity_class": "Battery", "entity_id": "sensor.lumi_lumi_sensor_switch_aq3_77665544_power", }, - ("sensor", "00:11:22:33:44:55:66:77-1-18"): { - "channels": ["multistate_input"], - "entity_class": "Text", - "entity_id": "sensor.lumi_lumi_sensor_switch_aq3_77665544_multistate_input", - }, }, "event_channels": ["1:0x0006"], "manufacturer": "LUMI",