mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
feat: Add unit of measurement to KNX number platform (#58353)
This commit is contained in:
parent
137a346d15
commit
85ecb7ce3a
@ -75,6 +75,7 @@ class KNXNumber(KnxEntity, NumberEntity, RestoreEntity):
|
|||||||
self._device.sensor_value.dpt_class.resolution,
|
self._device.sensor_value.dpt_class.resolution,
|
||||||
)
|
)
|
||||||
self._attr_unique_id = str(self._device.sensor_value.group_address)
|
self._attr_unique_id = str(self._device.sensor_value.group_address)
|
||||||
|
self._attr_unit_of_measurement = self._device.unit_of_measurement()
|
||||||
self._device.sensor_value.value = max(0, self._attr_min_value)
|
self._device.sensor_value.value = max(0, self._attr_min_value)
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
|
23
tests/components/knx/test_number.py
Normal file
23
tests/components/knx/test_number.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
"""Test KNX number."""
|
||||||
|
from homeassistant.components.knx.const import KNX_ADDRESS
|
||||||
|
from homeassistant.components.knx.schema import NumberSchema
|
||||||
|
from homeassistant.const import CONF_NAME, CONF_TYPE
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from .conftest import KNXTestKit
|
||||||
|
|
||||||
|
|
||||||
|
async def test_number_unit_of_measurement(hass: HomeAssistant, knx: KNXTestKit):
|
||||||
|
"""Test simple KNX number."""
|
||||||
|
test_address = "1/1/1"
|
||||||
|
await knx.setup_integration(
|
||||||
|
{
|
||||||
|
NumberSchema.PLATFORM_NAME: {
|
||||||
|
CONF_NAME: "test",
|
||||||
|
KNX_ADDRESS: test_address,
|
||||||
|
CONF_TYPE: "illuminance",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
assert len(hass.states.async_all()) == 1
|
||||||
|
assert hass.states.get("number.test").attributes.get("unit_of_measurement") == "lx"
|
Loading…
x
Reference in New Issue
Block a user