diff --git a/homeassistant/components/v2c/sensor.py b/homeassistant/components/v2c/sensor.py index 60ef582ce8d..64aacf8e49e 100644 --- a/homeassistant/components/v2c/sensor.py +++ b/homeassistant/components/v2c/sensor.py @@ -14,7 +14,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) 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.helpers.entity import Entity from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -27,21 +27,19 @@ _LOGGER = logging.getLogger(__name__) @dataclass -class V2CPowerRequiredKeysMixin: +class V2CRequiredKeysMixin: """Mixin for required keys.""" value_fn: Callable[[TrydanData], float] @dataclass -class V2CPowerSensorEntityDescription( - SensorEntityDescription, V2CPowerRequiredKeysMixin -): +class V2CSensorEntityDescription(SensorEntityDescription, V2CRequiredKeysMixin): """Describes an EVSE Power sensor entity.""" -POWER_SENSORS = ( - V2CPowerSensorEntityDescription( +TRYDAN_SENSORS = ( + V2CSensorEntityDescription( key="charge_power", translation_key="charge_power", native_unit_of_measurement=UnitOfPower.WATT, @@ -49,6 +47,38 @@ POWER_SENSORS = ( device_class=SensorDeviceClass.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] entities: list[Entity] = [ - V2CPowerSensorEntity(coordinator, description, config_entry.entry_id) - for description in POWER_SENSORS + V2CSensorBaseEntity(coordinator, description, config_entry.entry_id) + for description in TRYDAN_SENSORS ] async_add_entities(entities) @@ -70,11 +100,7 @@ async def async_setup_entry( class V2CSensorBaseEntity(V2CBaseEntity, SensorEntity): """Defines a base v2c sensor entity.""" - -class V2CPowerSensorEntity(V2CSensorBaseEntity): - """V2C Power sensor entity.""" - - entity_description: V2CPowerSensorEntityDescription + entity_description: V2CSensorEntityDescription _attr_icon = "mdi:ev-station" def __init__( diff --git a/homeassistant/components/v2c/strings.json b/homeassistant/components/v2c/strings.json index 3a87f91ebc5..7ef658b5daa 100644 --- a/homeassistant/components/v2c/strings.json +++ b/homeassistant/components/v2c/strings.json @@ -19,6 +19,18 @@ "sensor": { "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" } } }