mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Add 4 new sensors to V2C (#103634)
* add 4 sensors * no need for extra class
This commit is contained in:
parent
23578d8046
commit
0fdd929f54
@ -14,7 +14,7 @@ from homeassistant.components.sensor import (
|
|||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import UnitOfPower
|
from homeassistant.const import UnitOfEnergy, UnitOfPower, UnitOfTime
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -27,21 +27,19 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class V2CPowerRequiredKeysMixin:
|
class V2CRequiredKeysMixin:
|
||||||
"""Mixin for required keys."""
|
"""Mixin for required keys."""
|
||||||
|
|
||||||
value_fn: Callable[[TrydanData], float]
|
value_fn: Callable[[TrydanData], float]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class V2CPowerSensorEntityDescription(
|
class V2CSensorEntityDescription(SensorEntityDescription, V2CRequiredKeysMixin):
|
||||||
SensorEntityDescription, V2CPowerRequiredKeysMixin
|
|
||||||
):
|
|
||||||
"""Describes an EVSE Power sensor entity."""
|
"""Describes an EVSE Power sensor entity."""
|
||||||
|
|
||||||
|
|
||||||
POWER_SENSORS = (
|
TRYDAN_SENSORS = (
|
||||||
V2CPowerSensorEntityDescription(
|
V2CSensorEntityDescription(
|
||||||
key="charge_power",
|
key="charge_power",
|
||||||
translation_key="charge_power",
|
translation_key="charge_power",
|
||||||
native_unit_of_measurement=UnitOfPower.WATT,
|
native_unit_of_measurement=UnitOfPower.WATT,
|
||||||
@ -49,6 +47,38 @@ POWER_SENSORS = (
|
|||||||
device_class=SensorDeviceClass.POWER,
|
device_class=SensorDeviceClass.POWER,
|
||||||
value_fn=lambda evse_data: evse_data.charge_power,
|
value_fn=lambda evse_data: evse_data.charge_power,
|
||||||
),
|
),
|
||||||
|
V2CSensorEntityDescription(
|
||||||
|
key="charge_energy",
|
||||||
|
translation_key="charge_energy",
|
||||||
|
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||||
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
|
device_class=SensorDeviceClass.ENERGY,
|
||||||
|
value_fn=lambda evse_data: evse_data.charge_energy,
|
||||||
|
),
|
||||||
|
V2CSensorEntityDescription(
|
||||||
|
key="charge_time",
|
||||||
|
translation_key="charge_time",
|
||||||
|
native_unit_of_measurement=UnitOfTime.SECONDS,
|
||||||
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
|
device_class=SensorDeviceClass.DURATION,
|
||||||
|
value_fn=lambda evse_data: evse_data.charge_time,
|
||||||
|
),
|
||||||
|
V2CSensorEntityDescription(
|
||||||
|
key="house_power",
|
||||||
|
translation_key="house_power",
|
||||||
|
native_unit_of_measurement=UnitOfPower.WATT,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
device_class=SensorDeviceClass.POWER,
|
||||||
|
value_fn=lambda evse_data: evse_data.house_power,
|
||||||
|
),
|
||||||
|
V2CSensorEntityDescription(
|
||||||
|
key="fv_power",
|
||||||
|
translation_key="fv_power",
|
||||||
|
native_unit_of_measurement=UnitOfPower.WATT,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
device_class=SensorDeviceClass.POWER,
|
||||||
|
value_fn=lambda evse_data: evse_data.fv_power,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -61,8 +91,8 @@ async def async_setup_entry(
|
|||||||
coordinator: V2CUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator: V2CUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
|
|
||||||
entities: list[Entity] = [
|
entities: list[Entity] = [
|
||||||
V2CPowerSensorEntity(coordinator, description, config_entry.entry_id)
|
V2CSensorBaseEntity(coordinator, description, config_entry.entry_id)
|
||||||
for description in POWER_SENSORS
|
for description in TRYDAN_SENSORS
|
||||||
]
|
]
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
@ -70,11 +100,7 @@ async def async_setup_entry(
|
|||||||
class V2CSensorBaseEntity(V2CBaseEntity, SensorEntity):
|
class V2CSensorBaseEntity(V2CBaseEntity, SensorEntity):
|
||||||
"""Defines a base v2c sensor entity."""
|
"""Defines a base v2c sensor entity."""
|
||||||
|
|
||||||
|
entity_description: V2CSensorEntityDescription
|
||||||
class V2CPowerSensorEntity(V2CSensorBaseEntity):
|
|
||||||
"""V2C Power sensor entity."""
|
|
||||||
|
|
||||||
entity_description: V2CPowerSensorEntityDescription
|
|
||||||
_attr_icon = "mdi:ev-station"
|
_attr_icon = "mdi:ev-station"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
@ -19,6 +19,18 @@
|
|||||||
"sensor": {
|
"sensor": {
|
||||||
"charge_power": {
|
"charge_power": {
|
||||||
"name": "Charge power"
|
"name": "Charge power"
|
||||||
|
},
|
||||||
|
"charge_energy": {
|
||||||
|
"name": "Charge energy"
|
||||||
|
},
|
||||||
|
"charge_time": {
|
||||||
|
"name": "Charge time"
|
||||||
|
},
|
||||||
|
"house_power": {
|
||||||
|
"name": "House power"
|
||||||
|
},
|
||||||
|
"fv_power": {
|
||||||
|
"name": "Photovoltaic power"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user