EasyEnergy: Add two additional sensors to help pick the best hours (#90543)

This commit is contained in:
Sander Striker 2023-04-18 10:18:51 +02:00 committed by GitHub
parent 2530031454
commit f49dc65ff2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 4 deletions

View file

@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/easyenergy", "documentation": "https://www.home-assistant.io/integrations/easyenergy",
"iot_class": "cloud_polling", "iot_class": "cloud_polling",
"quality_scale": "platinum", "quality_scale": "platinum",
"requirements": ["easyenergy==0.2.3"] "requirements": ["easyenergy==0.3.0"]
} }

View file

@ -13,7 +13,13 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.config_entries import ConfigEntry 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.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import DeviceInfo
@ -175,6 +181,22 @@ SENSORS: tuple[EasyEnergySensorEntityDescription, ...] = (
icon="mdi:percent", icon="mdi:percent",
value_fn=lambda data: data.energy_today.pct_of_max_return, value_fn=lambda data: data.energy_today.pct_of_max_return,
), ),
EasyEnergySensorEntityDescription(
key="hours_priced_equal_or_lower",
name="Hours priced equal or lower than current - today",
service_type="today_energy_usage",
native_unit_of_measurement=UnitOfTime.HOURS,
icon="mdi:clock",
value_fn=lambda data: data.energy_today.hours_priced_equal_or_lower_usage,
),
EasyEnergySensorEntityDescription(
key="hours_priced_equal_or_higher",
name="Hours priced equal or higher than current - today",
service_type="today_energy_return",
native_unit_of_measurement=UnitOfTime.HOURS,
icon="mdi:clock",
value_fn=lambda data: data.energy_today.hours_priced_equal_or_higher_return,
),
) )

View file

@ -626,7 +626,7 @@ dynalite_devices==0.1.47
eagle100==0.1.1 eagle100==0.1.1
# homeassistant.components.easyenergy # homeassistant.components.easyenergy
easyenergy==0.2.3 easyenergy==0.3.0
# homeassistant.components.ebusd # homeassistant.components.ebusd
ebusdpy==0.0.17 ebusdpy==0.0.17

View file

@ -497,7 +497,7 @@ dynalite_devices==0.1.47
eagle100==0.1.1 eagle100==0.1.1
# homeassistant.components.easyenergy # homeassistant.components.easyenergy
easyenergy==0.2.3 easyenergy==0.3.0
# homeassistant.components.elgato # homeassistant.components.elgato
elgato==4.0.1 elgato==4.0.1

View file

@ -124,6 +124,25 @@ async def test_energy_usage_today(
assert not device_entry.model assert not device_entry.model
assert not device_entry.sw_version assert not device_entry.sw_version
# Usage hours priced equal or lower sensor
state = hass.states.get(
"sensor.easyenergy_today_energy_usage_hours_priced_equal_or_lower"
)
entry = entity_registry.async_get(
"sensor.easyenergy_today_energy_usage_hours_priced_equal_or_lower"
)
assert entry
assert state
assert (
entry.unique_id == f"{entry_id}_today_energy_usage_hours_priced_equal_or_lower"
)
assert state.state == "21"
assert (
state.attributes.get(ATTR_FRIENDLY_NAME)
== "Energy market price - Usage Hours priced equal or lower than current - today"
)
assert ATTR_DEVICE_CLASS not in state.attributes
@pytest.mark.freeze_time("2023-01-19 15:00:00") @pytest.mark.freeze_time("2023-01-19 15:00:00")
async def test_energy_return_today( async def test_energy_return_today(
@ -219,6 +238,26 @@ async def test_energy_return_today(
assert not device_entry.model assert not device_entry.model
assert not device_entry.sw_version assert not device_entry.sw_version
# Return hours priced equal or higher sensor
state = hass.states.get(
"sensor.easyenergy_today_energy_return_hours_priced_equal_or_higher"
)
entry = entity_registry.async_get(
"sensor.easyenergy_today_energy_return_hours_priced_equal_or_higher"
)
assert entry
assert state
assert (
entry.unique_id
== f"{entry_id}_today_energy_return_hours_priced_equal_or_higher"
)
assert state.state == "3"
assert (
state.attributes.get(ATTR_FRIENDLY_NAME)
== "Energy market price - Return Hours priced equal or higher than current - today"
)
assert ATTR_DEVICE_CLASS not in state.attributes
@pytest.mark.freeze_time("2023-01-19 10:00:00") @pytest.mark.freeze_time("2023-01-19 10:00:00")
async def test_gas_today( async def test_gas_today(