Use new unit enumerators in tibber (#84222)
parent
292294fb96
commit
3168b30535
|
@ -26,12 +26,12 @@ from homeassistant.components.sensor import (
|
|||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ELECTRIC_CURRENT_AMPERE,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
PERCENTAGE,
|
||||
SIGNAL_STRENGTH_DECIBELS,
|
||||
UnitOfElectricCurrent,
|
||||
UnitOfElectricPotential,
|
||||
UnitOfEnergy,
|
||||
UnitOfPower,
|
||||
)
|
||||
from homeassistant.core import Event, HomeAssistant, callback
|
||||
|
@ -93,48 +93,48 @@ RT_SENSORS: tuple[SensorEntityDescription, ...] = (
|
|||
key="accumulatedConsumption",
|
||||
name="accumulated consumption",
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||
state_class=SensorStateClass.TOTAL,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="accumulatedConsumptionLastHour",
|
||||
name="accumulated consumption current hour",
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="estimatedHourConsumption",
|
||||
name="Estimated consumption current hour",
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="accumulatedProduction",
|
||||
name="accumulated production",
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||
state_class=SensorStateClass.TOTAL,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="accumulatedProductionLastHour",
|
||||
name="accumulated production current hour",
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="lastMeterConsumption",
|
||||
name="last meter consumption",
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="lastMeterProduction",
|
||||
name="last meter production",
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
|
@ -162,21 +162,21 @@ RT_SENSORS: tuple[SensorEntityDescription, ...] = (
|
|||
key="currentL1",
|
||||
name="current L1",
|
||||
device_class=SensorDeviceClass.CURRENT,
|
||||
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="currentL2",
|
||||
name="current L2",
|
||||
device_class=SensorDeviceClass.CURRENT,
|
||||
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="currentL3",
|
||||
name="current L3",
|
||||
device_class=SensorDeviceClass.CURRENT,
|
||||
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
|
@ -219,7 +219,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
|
|||
key="peak_hour",
|
||||
name="Monthly peak hour consumption",
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="peak_hour_time",
|
||||
|
@ -230,7 +230,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
|
|||
key="month_cons",
|
||||
name="Monthly net consumption",
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
),
|
||||
)
|
||||
|
@ -575,12 +575,12 @@ class TibberDataCoordinator(DataUpdateCoordinator):
|
|||
async def _insert_statistics(self) -> None:
|
||||
"""Insert Tibber statistics."""
|
||||
for home in self._tibber_connection.get_homes():
|
||||
sensors = []
|
||||
sensors: list[tuple[str, bool, str]] = []
|
||||
if home.hourly_consumption_data:
|
||||
sensors.append(("consumption", False, ENERGY_KILO_WATT_HOUR))
|
||||
sensors.append(("consumption", False, UnitOfEnergy.KILO_WATT_HOUR))
|
||||
sensors.append(("totalCost", False, home.currency))
|
||||
if home.hourly_production_data:
|
||||
sensors.append(("production", True, ENERGY_KILO_WATT_HOUR))
|
||||
sensors.append(("production", True, UnitOfEnergy.KILO_WATT_HOUR))
|
||||
sensors.append(("profit", True, home.currency))
|
||||
|
||||
for sensor_type, is_production, unit in sensors:
|
||||
|
|
Loading…
Reference in New Issue