feat: Add unit of measurement to KNX number platform (#58353)
parent
137a346d15
commit
85ecb7ce3a
homeassistant/components/knx
tests/components/knx
|
@ -75,6 +75,7 @@ class KNXNumber(KnxEntity, NumberEntity, RestoreEntity):
|
|||
self._device.sensor_value.dpt_class.resolution,
|
||||
)
|
||||
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)
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
|
|
|
@ -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…
Reference in New Issue