This commit is contained in:
Julian Pawlowski 2025-05-19 09:51:52 +00:00
parent 71b81a9812
commit 1f8158ecea
6 changed files with 34 additions and 30 deletions

View file

@ -123,26 +123,28 @@ class TibberPricesBinarySensor(TibberPricesEntity, BinarySensorEntity):
return value
def _best_price_state(self) -> bool | None:
"""Return True if current price is within +flex% of the day's minimum price."""
price_data = self._get_current_price_data()
if not price_data:
"""Return True if the current time is within a best price period."""
if not self.coordinator.data:
return None
prices, current_price = price_data
min_price = min(prices)
flex = self._get_flex_option(CONF_BEST_PRICE_FLEX, DEFAULT_BEST_PRICE_FLEX)
threshold = min_price * (1 + flex)
return current_price <= threshold
attrs = self._get_price_intervals_attributes(reverse_sort=False)
if not attrs or "interval_start" not in attrs or "interval_end" not in attrs:
return None
now = dt_util.now()
start = attrs.get("interval_start")
end = attrs.get("interval_end")
return start <= now < end if start and end else None
def _peak_price_state(self) -> bool | None:
"""Return True if current price is within -flex% of the day's maximum price."""
price_data = self._get_current_price_data()
if not price_data:
"""Return True if the current time is within a peak price period."""
if not self.coordinator.data:
return None
prices, current_price = price_data
max_price = max(prices)
flex = self._get_flex_option(CONF_PEAK_PRICE_FLEX, DEFAULT_PEAK_PRICE_FLEX)
threshold = max_price * (1 - flex)
return current_price >= threshold
attrs = self._get_price_intervals_attributes(reverse_sort=True)
if not attrs or "interval_start" not in attrs or "interval_end" not in attrs:
return None
now = dt_util.now()
start = attrs.get("interval_start")
end = attrs.get("interval_end")
return start <= now < end if start and end else None
def _tomorrow_data_available_state(self) -> bool | None:
"""Return True if tomorrow's data is fully available, False if not, None if unknown."""
@ -151,7 +153,11 @@ class TibberPricesBinarySensor(TibberPricesEntity, BinarySensorEntity):
price_info = self.coordinator.data["data"]["viewer"]["homes"][0]["currentSubscription"]["priceInfo"]
tomorrow_prices = price_info.get("tomorrow", [])
interval_count = len(tomorrow_prices)
return interval_count in TOMORROW_INTERVAL_COUNTS
if interval_count in TOMORROW_INTERVAL_COUNTS:
return True
if interval_count == 0:
return False
return False
def _get_tomorrow_data_available_attributes(self) -> dict | None:
"""Return attributes for tomorrow_data_available binary sensor."""

View file

@ -97,10 +97,9 @@
"usage_tips": "Ein positiver Prozentsatz bedeutet, dass die Preise dieses Monats überdurchschnittlich sind, negativ bedeutet unterdurchschnittlich"
},
"data_timestamp": {
"name": "Zeitstempel der neuesten Daten",
"description": "Wann die neuesten Preisdaten empfangen wurden",
"long_description": "Zeigt den Zeitstempel des letzten Preisaktualisierung von Tibber",
"usage_tips": "Nutze dies, um zu überprüfen, wann die Preisinformationen zuletzt aktualisiert wurden"
"name": "Ablauf der Preisdaten",
"description": "Zeitstempel des letzten verfügbaren Preisintervalls",
"long_description": "Zeigt den Zeitstempel des letzten verfügbaren Preisintervalls von deinem Tibber-Abonnement an"
},
"price_forecast": {
"name": "Preisprognose",
@ -135,4 +134,4 @@
"usage_tips": "Nutze dies, um den Verbindungsstatus zur Tibber API zu überwachen"
}
}
}
}

View file

@ -97,10 +97,9 @@
"usage_tips": "A positive percentage means this month's prices are above average, negative means below average"
},
"data_timestamp": {
"name": "Latest Data Timestamp",
"description": "When the latest price data was received",
"long_description": "Shows the timestamp of the most recent price data update from Tibber",
"usage_tips": "Use this to check when price information was last updated"
"name": "Price Data Expiration",
"description": "Timestamp of the latest available price data interval",
"long_description": "Shows the timestamp of the latest available price data interval from your Tibber subscription"
},
"price_forecast": {
"name": "Price Forecast",
@ -135,4 +134,4 @@
"usage_tips": "Use this to monitor the connection status to the Tibber API"
}
}
}
}

View file

@ -180,7 +180,7 @@ DIAGNOSTIC_SENSORS = (
SensorEntityDescription(
key="data_timestamp",
translation_key="data_timestamp",
name="Latest Data Available",
name="Data Expiration",
icon="mdi:clock-check",
device_class=SensorDeviceClass.TIMESTAMP,
entity_category=EntityCategory.DIAGNOSTIC,

View file

@ -86,7 +86,7 @@
"name": "Monatliche Preisbewertung"
},
"data_timestamp": {
"name": "Zeitstempel der neuesten Daten"
"name": "Ablauf der Preisdaten"
},
"next_interval_price": {
"name": "Strompreis nächstes Intervall"

View file

@ -104,7 +104,7 @@
"name": "Monthly Price Rating"
},
"data_timestamp": {
"name": "Latest Data Available"
"name": "Price Data Expiration"
},
"price_forecast": {
"name": "Price Forecast"