From 8fac092156caa4aed08b7d9f9bfae3c0052789c2 Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Thu, 4 Jan 2024 13:38:48 +0100 Subject: [PATCH 1/2] Add zwave_js voltage sensor suggested precision --- homeassistant/components/zwave_js/sensor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/zwave_js/sensor.py b/homeassistant/components/zwave_js/sensor.py index 798d4bf92bc3e4..9e95d430a4cde5 100644 --- a/homeassistant/components/zwave_js/sensor.py +++ b/homeassistant/components/zwave_js/sensor.py @@ -128,6 +128,7 @@ device_class=SensorDeviceClass.VOLTAGE, state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=UnitOfElectricPotential.VOLT, + suggested_display_precision=0, ), ( ENTITY_DESC_KEY_VOLTAGE, From 96a8d545e195797118aed683b7741425a38d8a9c Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Thu, 4 Jan 2024 13:46:52 +0100 Subject: [PATCH 2/2] Test voltage sensor suggested precision --- tests/components/zwave_js/test_sensor.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/components/zwave_js/test_sensor.py b/tests/components/zwave_js/test_sensor.py index 390d9631f232de..0fe3e32043b434 100644 --- a/tests/components/zwave_js/test_sensor.py +++ b/tests/components/zwave_js/test_sensor.py @@ -165,7 +165,10 @@ async def test_invalid_multilevel_sensor_scale( async def test_energy_sensors( - hass: HomeAssistant, hank_binary_switch, integration + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + hank_binary_switch, + integration, ) -> None: """Test power and energy sensors.""" state = hass.states.get(POWER_SENSOR) @@ -191,6 +194,13 @@ async def test_energy_sensors( assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfElectricPotential.VOLT assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.VOLTAGE + entity_entry = entity_registry.async_get(VOLTAGE_SENSOR) + + assert entity_entry is not None + sensor_options = entity_entry.options.get("sensor") + assert sensor_options is not None + assert sensor_options["suggested_display_precision"] == 0 + state = hass.states.get(CURRENT_SENSOR) assert state