Energyzero - Add sensor entity to pick best hours (#98916)

* Add entity to pick best hours

* Add entity also to diagnostics

* Remove string translation that doesn't exists

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
Klaas Schoute 2023-08-23 23:02:19 +02:00 committed by GitHub
parent 816f834807
commit d8f0c090cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 88 additions and 4 deletions

View file

@ -13,7 +13,13 @@ from homeassistant.components.sensor import (
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CURRENCY_EURO, PERCENTAGE, UnitOfEnergy, UnitOfVolume
from homeassistant.const import (
CURRENCY_EURO,
PERCENTAGE,
UnitOfEnergy,
UnitOfTime,
UnitOfVolume,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -114,6 +120,14 @@ SENSORS: tuple[EnergyZeroSensorEntityDescription, ...] = (
icon="mdi:percent",
value_fn=lambda data: data.energy_today.pct_of_max_price,
),
EnergyZeroSensorEntityDescription(
key="hours_priced_equal_or_lower",
translation_key="hours_priced_equal_or_lower",
service_type="today_energy",
native_unit_of_measurement=UnitOfTime.HOURS,
icon="mdi:clock",
value_fn=lambda data: data.energy_today.hours_priced_equal_or_lower,
),
)