1 """Support for Pure Energie sensors."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
9 DOMAIN
as SENSOR_DOMAIN,
12 SensorEntityDescription,
21 from .
import PureEnergieConfigEntry
22 from .const
import DOMAIN
23 from .coordinator
import PureEnergieData, PureEnergieDataUpdateCoordinator
26 @dataclass(frozen=True, kw_only=True)
28 """Describes a Pure Energie sensor entity."""
30 value_fn: Callable[[PureEnergieData], int | float]
33 SENSORS: tuple[PureEnergieSensorEntityDescription, ...] = (
36 translation_key=
"power_flow",
37 native_unit_of_measurement=UnitOfPower.WATT,
38 device_class=SensorDeviceClass.POWER,
39 state_class=SensorStateClass.MEASUREMENT,
40 value_fn=
lambda data: data.smartbridge.power_flow,
43 key=
"energy_consumption_total",
44 translation_key=
"energy_consumption_total",
45 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
46 device_class=SensorDeviceClass.ENERGY,
47 state_class=SensorStateClass.TOTAL_INCREASING,
48 value_fn=
lambda data: data.smartbridge.energy_consumption_total,
51 key=
"energy_production_total",
52 translation_key=
"energy_production_total",
53 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
54 device_class=SensorDeviceClass.ENERGY,
55 state_class=SensorStateClass.TOTAL_INCREASING,
56 value_fn=
lambda data: data.smartbridge.energy_production_total,
63 entry: PureEnergieConfigEntry,
64 async_add_entities: AddEntitiesCallback,
66 """Set up Pure Energie Sensors based on a config entry."""
69 description=description,
72 for description
in SENSORS
77 CoordinatorEntity[PureEnergieDataUpdateCoordinator], SensorEntity
79 """Defines an Pure Energie sensor."""
81 _attr_has_entity_name =
True
82 entity_description: PureEnergieSensorEntityDescription
87 description: PureEnergieSensorEntityDescription,
88 entry: PureEnergieConfigEntry,
90 """Initialize Pure Energie sensor."""
91 super().
__init__(coordinator=entry.runtime_data)
95 f
"{entry.runtime_data.data.device.n2g_id}_{description.key}"
98 identifiers={(DOMAIN, entry.runtime_data.data.device.n2g_id)},
99 configuration_url=f
"http://{entry.runtime_data.config_entry.data[CONF_HOST]}",
100 sw_version=entry.runtime_data.data.device.firmware,
101 manufacturer=entry.runtime_data.data.device.manufacturer,
102 model=entry.runtime_data.data.device.model,
108 """Return the state of the sensor."""
None __init__(self, *PureEnergieSensorEntityDescription description, PureEnergieConfigEntry entry)
int|float native_value(self)
None async_setup_entry(HomeAssistant hass, PureEnergieConfigEntry entry, AddEntitiesCallback async_add_entities)