Use entity descriptions classes in Forecast.Solar (#53553)

This commit is contained in:
Franck Nijhof 2021-07-27 17:45:47 +02:00 committed by GitHub
parent 72a98550b6
commit f1eb35b1a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 40 deletions

View file

@ -13,7 +13,7 @@ from homeassistant.const import (
POWER_WATT,
)
from .models import ForecastSolarSensor
from .models import ForecastSolarSensorEntityDescription
DOMAIN = "forecast_solar"
@ -24,32 +24,32 @@ CONF_DAMPING = "damping"
ATTR_ENTRY_TYPE: Final = "entry_type"
ENTRY_TYPE_SERVICE: Final = "service"
SENSORS: list[ForecastSolarSensor] = [
ForecastSolarSensor(
SENSORS: tuple[ForecastSolarSensorEntityDescription, ...] = (
ForecastSolarSensorEntityDescription(
key="energy_production_today",
name="Estimated Energy Production - Today",
state=lambda estimate: estimate.energy_production_today / 1000,
device_class=DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
),
ForecastSolarSensor(
ForecastSolarSensorEntityDescription(
key="energy_production_tomorrow",
name="Estimated Energy Production - Tomorrow",
state=lambda estimate: estimate.energy_production_tomorrow / 1000,
device_class=DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
),
ForecastSolarSensor(
ForecastSolarSensorEntityDescription(
key="power_highest_peak_time_today",
name="Highest Power Peak Time - Today",
device_class=DEVICE_CLASS_TIMESTAMP,
),
ForecastSolarSensor(
ForecastSolarSensorEntityDescription(
key="power_highest_peak_time_tomorrow",
name="Highest Power Peak Time - Tomorrow",
device_class=DEVICE_CLASS_TIMESTAMP,
),
ForecastSolarSensor(
ForecastSolarSensorEntityDescription(
key="power_production_now",
name="Estimated Power Production - Now",
device_class=DEVICE_CLASS_POWER,
@ -57,7 +57,7 @@ SENSORS: list[ForecastSolarSensor] = [
state_class=STATE_CLASS_MEASUREMENT,
unit_of_measurement=POWER_WATT,
),
ForecastSolarSensor(
ForecastSolarSensorEntityDescription(
key="power_production_next_hour",
state=lambda estimate: estimate.power_production_at_time(
estimate.now() + timedelta(hours=1)
@ -68,7 +68,7 @@ SENSORS: list[ForecastSolarSensor] = [
entity_registry_enabled_default=False,
unit_of_measurement=POWER_WATT,
),
ForecastSolarSensor(
ForecastSolarSensorEntityDescription(
key="power_production_next_12hours",
state=lambda estimate: estimate.power_production_at_time(
estimate.now() + timedelta(hours=12)
@ -79,7 +79,7 @@ SENSORS: list[ForecastSolarSensor] = [
entity_registry_enabled_default=False,
unit_of_measurement=POWER_WATT,
),
ForecastSolarSensor(
ForecastSolarSensorEntityDescription(
key="power_production_next_24hours",
state=lambda estimate: estimate.power_production_at_time(
estimate.now() + timedelta(hours=24)
@ -90,18 +90,18 @@ SENSORS: list[ForecastSolarSensor] = [
entity_registry_enabled_default=False,
unit_of_measurement=POWER_WATT,
),
ForecastSolarSensor(
ForecastSolarSensorEntityDescription(
key="energy_current_hour",
name="Estimated Energy Production - This Hour",
state=lambda estimate: estimate.energy_current_hour / 1000,
device_class=DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
),
ForecastSolarSensor(
ForecastSolarSensorEntityDescription(
key="energy_next_hour",
state=lambda estimate: estimate.sum_energy_production(1) / 1000,
name="Estimated Energy Production - Next Hour",
device_class=DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
),
]
)