From b28ad1282a8b31b604d5bd2496a7fa75ad2c7e77 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Wed, 12 Oct 2022 11:56:18 +0200 Subject: [PATCH] Use percentage constant as unit in LaMetric brightness (#80162) --- homeassistant/components/lametric/number.py | 3 ++- tests/components/lametric/test_number.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/lametric/number.py b/homeassistant/components/lametric/number.py index 9275160f497..c82fded83c8 100644 --- a/homeassistant/components/lametric/number.py +++ b/homeassistant/components/lametric/number.py @@ -9,6 +9,7 @@ from demetriek import Device, LaMetricDevice from homeassistant.components.number import NumberEntity, NumberEntityDescription from homeassistant.config_entries import ConfigEntry +from homeassistant.const import PERCENTAGE from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -43,7 +44,7 @@ NUMBERS = [ native_step=1, native_min_value=0, native_max_value=100, - native_unit_of_measurement="%", + native_unit_of_measurement=PERCENTAGE, value_fn=lambda device: device.display.brightness, set_value_fn=lambda device, bri: device.display(brightness=int(bri)), ), diff --git a/tests/components/lametric/test_number.py b/tests/components/lametric/test_number.py index f80b2214577..2ecfc43246e 100644 --- a/tests/components/lametric/test_number.py +++ b/tests/components/lametric/test_number.py @@ -19,6 +19,7 @@ from homeassistant.const import ( ATTR_FRIENDLY_NAME, ATTR_ICON, ATTR_UNIT_OF_MEASUREMENT, + PERCENTAGE, STATE_UNAVAILABLE, ) from homeassistant.core import HomeAssistant @@ -46,7 +47,7 @@ async def test_brightness( assert state.attributes.get(ATTR_MAX) == 100 assert state.attributes.get(ATTR_MIN) == 0 assert state.attributes.get(ATTR_STEP) == 1 - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "%" + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE assert state.state == "100" entry = entity_registry.async_get(state.entity_id)