mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Map abode units to HA units (#99323)
This commit is contained in:
parent
e56db78b27
commit
5f05d0d7e9
@ -14,13 +14,18 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import LIGHT_LUX
|
from homeassistant.const import LIGHT_LUX, PERCENTAGE, UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import AbodeDevice, AbodeSystem
|
from . import AbodeDevice, AbodeSystem
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
ABODE_TEMPERATURE_UNIT_HA_UNIT = {
|
||||||
|
CONST.UNIT_FAHRENHEIT: UnitOfTemperature.FAHRENHEIT,
|
||||||
|
CONST.UNIT_CELSIUS: UnitOfTemperature.CELSIUS,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AbodeSensorDescriptionMixin:
|
class AbodeSensorDescriptionMixin:
|
||||||
@ -39,13 +44,15 @@ SENSOR_TYPES: tuple[AbodeSensorDescription, ...] = (
|
|||||||
AbodeSensorDescription(
|
AbodeSensorDescription(
|
||||||
key=CONST.TEMP_STATUS_KEY,
|
key=CONST.TEMP_STATUS_KEY,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
native_unit_of_measurement_fn=lambda device: device.temp_unit,
|
native_unit_of_measurement_fn=lambda device: ABODE_TEMPERATURE_UNIT_HA_UNIT[
|
||||||
|
device.temp_unit
|
||||||
|
],
|
||||||
value_fn=lambda device: cast(float, device.temp),
|
value_fn=lambda device: cast(float, device.temp),
|
||||||
),
|
),
|
||||||
AbodeSensorDescription(
|
AbodeSensorDescription(
|
||||||
key=CONST.HUMI_STATUS_KEY,
|
key=CONST.HUMI_STATUS_KEY,
|
||||||
device_class=SensorDeviceClass.HUMIDITY,
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
native_unit_of_measurement_fn=lambda device: device.humidity_unit,
|
native_unit_of_measurement_fn=lambda _: PERCENTAGE,
|
||||||
value_fn=lambda device: cast(float, device.humidity),
|
value_fn=lambda device: cast(float, device.humidity),
|
||||||
),
|
),
|
||||||
AbodeSensorDescription(
|
AbodeSensorDescription(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user