Add demand window sensor for amberelectric (#121356)

This commit is contained in:
Xidorn Quan
2024-07-06 20:28:52 +10:00
committed by GitHub
parent be0cf545b2
commit 2bc7904b51
5 changed files with 123 additions and 15 deletions

View File

@@ -71,6 +71,18 @@ class AmberPriceSpikeBinarySensor(AmberPriceGridSensor):
}
class AmberDemandWindowBinarySensor(AmberPriceGridSensor):
"""Sensor to show whether demand window is active."""
@property
def is_on(self) -> bool | None:
"""Return true if the binary sensor is on."""
grid = self.coordinator.data["grid"]
if "demand_window" in grid:
return grid["demand_window"] # type: ignore[no-any-return]
return None
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
@@ -83,6 +95,14 @@ async def async_setup_entry(
key="price_spike",
name=f"{entry.title} - Price Spike",
)
async_add_entities(
[AmberPriceSpikeBinarySensor(coordinator, price_spike_description)]
demand_window_description = BinarySensorEntityDescription(
key="demand_window",
name=f"{entry.title} - Demand Window",
translation_key="demand_window",
)
async_add_entities(
[
AmberPriceSpikeBinarySensor(coordinator, price_spike_description),
AmberDemandWindowBinarySensor(coordinator, demand_window_description),
]
)