From 61ab2b0c60ceb58cfd7dabec99c125830d2185d3 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Mon, 16 Aug 2021 12:30:52 -0400 Subject: [PATCH] Use zwave_js.number platform for Basic CC values (#54512) * Use zwave_js.number platform for some Basic CC values * Remove Basic CC sensor discovery schema * update comment * update comment --- homeassistant/components/zwave_js/discovery.py | 15 ++++++++++++--- homeassistant/components/zwave_js/sensor.py | 16 ---------------- tests/components/zwave_js/common.py | 2 +- tests/components/zwave_js/test_number.py | 14 ++++++++++++++ tests/components/zwave_js/test_sensor.py | 11 ----------- 5 files changed, 27 insertions(+), 31 deletions(-) diff --git a/homeassistant/components/zwave_js/discovery.py b/homeassistant/components/zwave_js/discovery.py index 588b4c76472..77590e780a5 100644 --- a/homeassistant/components/zwave_js/discovery.py +++ b/homeassistant/components/zwave_js/discovery.py @@ -542,10 +542,10 @@ DISCOVERY_SCHEMAS = [ allow_multi=True, entity_registry_enabled_default=False, ), - # sensor for basic CC + # number for Basic CC ZWaveDiscoverySchema( - platform="sensor", - hint="numeric_sensor", + platform="number", + hint="Basic", primary_value=ZWaveValueDiscoverySchema( command_class={ CommandClass.BASIC, @@ -553,6 +553,15 @@ DISCOVERY_SCHEMAS = [ type={"number"}, property={"currentValue"}, ), + required_values=[ + ZWaveValueDiscoverySchema( + command_class={ + CommandClass.BASIC, + }, + type={"number"}, + property={"targetValue"}, + ) + ], entity_registry_enabled_default=False, ), # binary switches diff --git a/homeassistant/components/zwave_js/sensor.py b/homeassistant/components/zwave_js/sensor.py index aa163fa8bd9..deacf3d874a 100644 --- a/homeassistant/components/zwave_js/sensor.py +++ b/homeassistant/components/zwave_js/sensor.py @@ -198,22 +198,6 @@ class ZWaveStringSensor(ZwaveSensorBase): class ZWaveNumericSensor(ZwaveSensorBase): """Representation of a Z-Wave Numeric sensor.""" - def __init__( - self, - config_entry: ConfigEntry, - client: ZwaveClient, - info: ZwaveDiscoveryInfo, - ) -> None: - """Initialize a ZWaveNumericSensor entity.""" - super().__init__(config_entry, client, info) - - # Entity class attributes - if self.info.primary_value.command_class == CommandClass.BASIC: - self._attr_name = self.generate_name( - include_value_name=True, - alternate_value_name=self.info.primary_value.command_class_name, - ) - @property def native_value(self) -> float: """Return state of the sensor.""" diff --git a/tests/components/zwave_js/common.py b/tests/components/zwave_js/common.py index 44943fed9fb..0c6b19698a9 100644 --- a/tests/components/zwave_js/common.py +++ b/tests/components/zwave_js/common.py @@ -16,7 +16,7 @@ NOTIFICATION_MOTION_BINARY_SENSOR = ( ) NOTIFICATION_MOTION_SENSOR = "sensor.multisensor_6_home_security_motion_sensor_status" INDICATOR_SENSOR = "sensor.z_wave_thermostat_indicator_value" -BASIC_SENSOR = "sensor.livingroomlight_basic" +BASIC_NUMBER_ENTITY = "number.livingroomlight_basic" PROPERTY_DOOR_STATUS_BINARY_SENSOR = ( "binary_sensor.august_smart_lock_pro_3rd_gen_the_current_status_of_the_door" ) diff --git a/tests/components/zwave_js/test_number.py b/tests/components/zwave_js/test_number.py index b7d83068bea..6439d034587 100644 --- a/tests/components/zwave_js/test_number.py +++ b/tests/components/zwave_js/test_number.py @@ -1,6 +1,10 @@ """Test the Z-Wave JS number platform.""" from zwave_js_server.event import Event +from homeassistant.helpers import entity_registry as er + +from .common import BASIC_NUMBER_ENTITY + NUMBER_ENTITY = "number.thermostat_hvac_valve_control" @@ -67,3 +71,13 @@ async def test_number(hass, client, aeotec_radiator_thermostat, integration): state = hass.states.get(NUMBER_ENTITY) assert state.state == "99.0" + + +async def test_disabled_basic_number(hass, ge_in_wall_dimmer_switch, integration): + """Test number is created from Basic CC and is disabled.""" + ent_reg = er.async_get(hass) + entity_entry = ent_reg.async_get(BASIC_NUMBER_ENTITY) + + assert entity_entry + assert entity_entry.disabled + assert entity_entry.disabled_by == er.DISABLED_INTEGRATION diff --git a/tests/components/zwave_js/test_sensor.py b/tests/components/zwave_js/test_sensor.py index 04583559421..268d8ee1380 100644 --- a/tests/components/zwave_js/test_sensor.py +++ b/tests/components/zwave_js/test_sensor.py @@ -28,7 +28,6 @@ from homeassistant.helpers import entity_registry as er from .common import ( AIR_TEMPERATURE_SENSOR, - BASIC_SENSOR, CURRENT_SENSOR, DATETIME_LAST_RESET, DATETIME_ZERO, @@ -131,16 +130,6 @@ async def test_disabled_indcator_sensor( assert entity_entry.disabled_by == er.DISABLED_INTEGRATION -async def test_disabled_basic_sensor(hass, ge_in_wall_dimmer_switch, integration): - """Test sensor is created from Basic CC and is disabled.""" - ent_reg = er.async_get(hass) - entity_entry = ent_reg.async_get(BASIC_SENSOR) - - assert entity_entry - assert entity_entry.disabled - assert entity_entry.disabled_by == er.DISABLED_INTEGRATION - - async def test_config_parameter_sensor(hass, lock_id_lock_as_id150, integration): """Test config parameter sensor is created.""" ent_reg = er.async_get(hass)