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:
parent
816f834807
commit
d8f0c090cf
6 changed files with 88 additions and 4 deletions
|
@ -50,6 +50,7 @@ async def async_get_config_entry_diagnostics(
|
|||
"highest_price_time": coordinator.data.energy_today.highest_price_time,
|
||||
"lowest_price_time": coordinator.data.energy_today.lowest_price_time,
|
||||
"percentage_of_max": coordinator.data.energy_today.pct_of_max_price,
|
||||
"hours_priced_equal_or_lower": coordinator.data.energy_today.hours_priced_equal_or_lower,
|
||||
},
|
||||
"gas": {
|
||||
"current_hour_price": get_gas_price(coordinator.data, 0),
|
||||
|
|
|
@ -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,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -37,9 +37,6 @@
|
|||
},
|
||||
"hours_priced_equal_or_lower": {
|
||||
"name": "Hours priced equal or lower than current - today"
|
||||
},
|
||||
"hours_priced_equal_or_higher": {
|
||||
"name": "Hours priced equal or higher than current - today"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
'average_price': 0.37,
|
||||
'current_hour_price': 0.49,
|
||||
'highest_price_time': '2022-12-07T16:00:00+00:00',
|
||||
'hours_priced_equal_or_lower': 23,
|
||||
'lowest_price_time': '2022-12-07T02:00:00+00:00',
|
||||
'max_price': 0.55,
|
||||
'min_price': 0.26,
|
||||
|
@ -26,6 +27,7 @@
|
|||
'average_price': 0.37,
|
||||
'current_hour_price': 0.49,
|
||||
'highest_price_time': '2022-12-07T16:00:00+00:00',
|
||||
'hours_priced_equal_or_lower': 23,
|
||||
'lowest_price_time': '2022-12-07T02:00:00+00:00',
|
||||
'max_price': 0.55,
|
||||
'min_price': 0.26,
|
||||
|
|
|
@ -651,6 +651,71 @@
|
|||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor[sensor.energyzero_today_energy_hours_priced_equal_or_lower-today_energy_hours_priced_equal_or_lower-today_energy]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'attribution': 'Data provided by EnergyZero',
|
||||
'friendly_name': 'Energy market price Hours priced equal or lower than current - today',
|
||||
'icon': 'mdi:clock',
|
||||
'unit_of_measurement': <UnitOfTime.HOURS: 'h'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.energyzero_today_energy_hours_priced_equal_or_lower',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '23',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor[sensor.energyzero_today_energy_hours_priced_equal_or_lower-today_energy_hours_priced_equal_or_lower-today_energy].1
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.energyzero_today_energy_hours_priced_equal_or_lower',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': 'mdi:clock',
|
||||
'original_name': 'Hours priced equal or lower than current - today',
|
||||
'platform': 'energyzero',
|
||||
'supported_features': 0,
|
||||
'translation_key': 'hours_priced_equal_or_lower',
|
||||
'unit_of_measurement': <UnitOfTime.HOURS: 'h'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor[sensor.energyzero_today_energy_hours_priced_equal_or_lower-today_energy_hours_priced_equal_or_lower-today_energy].2
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': None,
|
||||
'connections': set({
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': <DeviceEntryType.SERVICE: 'service'>,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'is_new': False,
|
||||
'manufacturer': 'EnergyZero',
|
||||
'model': None,
|
||||
'name': 'Energy market price',
|
||||
'name_by_user': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': None,
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor[sensor.energyzero_today_energy_max_price-today_energy_max_price-today_energy]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
|
|
|
@ -41,6 +41,11 @@ pytestmark = [pytest.mark.freeze_time("2022-12-07 15:00:00")]
|
|||
"today_energy_highest_price_time",
|
||||
"today_energy",
|
||||
),
|
||||
(
|
||||
"sensor.energyzero_today_energy_hours_priced_equal_or_lower",
|
||||
"today_energy_hours_priced_equal_or_lower",
|
||||
"today_energy",
|
||||
),
|
||||
(
|
||||
"sensor.energyzero_today_gas_current_hour_price",
|
||||
"today_gas_current_hour_price",
|
||||
|
|
Loading…
Add table
Reference in a new issue