mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Add Edl21 unit of measurement mapping (#64926)
This commit is contained in:
parent
8b5e76b898
commit
a4904bd9bc
@ -15,7 +15,14 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_NAME
|
from homeassistant.const import (
|
||||||
|
CONF_NAME,
|
||||||
|
ELECTRIC_CURRENT_AMPERE,
|
||||||
|
ELECTRIC_POTENTIAL_VOLT,
|
||||||
|
ENERGY_KILO_WATT_HOUR,
|
||||||
|
ENERGY_WATT_HOUR,
|
||||||
|
POWER_WATT,
|
||||||
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.dispatcher import (
|
from homeassistant.helpers.dispatcher import (
|
||||||
@ -238,6 +245,14 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|||||||
|
|
||||||
SENSORS = {desc.key: desc for desc in SENSOR_TYPES}
|
SENSORS = {desc.key: desc for desc in SENSOR_TYPES}
|
||||||
|
|
||||||
|
SENSOR_UNIT_MAPPING = {
|
||||||
|
"Wh": ENERGY_WATT_HOUR,
|
||||||
|
"kWh": ENERGY_KILO_WATT_HOUR,
|
||||||
|
"W": POWER_WATT,
|
||||||
|
"A": ELECTRIC_CURRENT_AMPERE,
|
||||||
|
"V": ELECTRIC_POTENTIAL_VOLT,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(
|
async def async_setup_platform(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -435,4 +450,9 @@ class EDL21Entity(SensorEntity):
|
|||||||
@property
|
@property
|
||||||
def native_unit_of_measurement(self):
|
def native_unit_of_measurement(self):
|
||||||
"""Return the unit of measurement."""
|
"""Return the unit of measurement."""
|
||||||
return self._telegram.get("unit")
|
unit = self._telegram.get("unit")
|
||||||
|
|
||||||
|
if unit is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return SENSOR_UNIT_MAPPING[unit]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user