feat: Add unit of measurement to KNX number platform ()

pull/58340/head
Marvin Wichmann 2021-10-24 22:16:19 +02:00 committed by GitHub
parent 137a346d15
commit 85ecb7ce3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions
homeassistant/components/knx
tests/components/knx

View File

@ -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:

View 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"