Skip to content

Commit

Permalink
Add next gas price #73
Browse files Browse the repository at this point in the history
  • Loading branch information
fsaris committed Nov 18, 2023
1 parent d1bfccd commit fda3dc5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions custom_components/zonneplan_one/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ class ZonneplanBinarySensorEntityDescription(BinarySensorEntityDescription):
none_value_behaviour=NONE_USE_PREVIOUS,
daily_update_hour=6,
),
"next_tariff_gas": ZonneplanSensorEntityDescription(
key="summary_data.gas_price_next",
name="Zonneplan next gas tariff",
icon="mdi:cash",
value_factor=0.0000001,
native_unit_of_measurement=f"{CURRENCY_EURO}/{UnitOfVolume.CUBIC_METERS}",
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=True,
none_value_behaviour=NONE_USE_PREVIOUS,
daily_update_hour=18,
),
"status_message": ZonneplanSensorEntityDescription(
key="summary_data.usage.status_message",
name="Zonneplan status message",
Expand Down
11 changes: 11 additions & 0 deletions custom_components/zonneplan_one/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ def getGasPriceFromSummary(summary):

return None

def getNextGasPriceFromSummary(summary):
if not "price_per_hour" in summary:
return None

for hour in reversed(summary["price_per_hour"]):
if "gas_price" in hour:
return hour["gas_price"]

return None

class ZonneplanUpdateCoordinator(DataUpdateCoordinator):
"""Zonneplan status update coordinator"""

Expand Down Expand Up @@ -103,6 +113,7 @@ async def _fetch_data(self) -> dict:
if summary:
result[uuid]["summary_data"] = summary
result[uuid]["summary_data"]["gas_price"] = getGasPriceFromSummary(summary)
result[uuid]["summary_data"]["gas_price_next"] = getNextGasPriceFromSummary(summary)
summary_retrieved = True

if "charge_point_installation" in connection:
Expand Down

0 comments on commit fda3dc5

Please sign in to comment.