diff --git a/custom_components/tibber_prices/binary_sensor.py b/custom_components/tibber_prices/binary_sensor.py index 38f7ab0..b9fa791 100644 --- a/custom_components/tibber_prices/binary_sensor.py +++ b/custom_components/tibber_prices/binary_sensor.py @@ -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.""" diff --git a/custom_components/tibber_prices/custom_translations/de.json b/custom_components/tibber_prices/custom_translations/de.json index 664a32b..55adf41 100644 --- a/custom_components/tibber_prices/custom_translations/de.json +++ b/custom_components/tibber_prices/custom_translations/de.json @@ -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" } } -} \ No newline at end of file +} diff --git a/custom_components/tibber_prices/custom_translations/en.json b/custom_components/tibber_prices/custom_translations/en.json index d92ea56..3d264e4 100644 --- a/custom_components/tibber_prices/custom_translations/en.json +++ b/custom_components/tibber_prices/custom_translations/en.json @@ -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" } } -} \ No newline at end of file +} diff --git a/custom_components/tibber_prices/sensor.py b/custom_components/tibber_prices/sensor.py index 4c5b324..e1975b5 100644 --- a/custom_components/tibber_prices/sensor.py +++ b/custom_components/tibber_prices/sensor.py @@ -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, diff --git a/custom_components/tibber_prices/translations/de.json b/custom_components/tibber_prices/translations/de.json index 209ebb9..db54500 100644 --- a/custom_components/tibber_prices/translations/de.json +++ b/custom_components/tibber_prices/translations/de.json @@ -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" diff --git a/custom_components/tibber_prices/translations/en.json b/custom_components/tibber_prices/translations/en.json index 93bb23a..8b77cae 100644 --- a/custom_components/tibber_prices/translations/en.json +++ b/custom_components/tibber_prices/translations/en.json @@ -104,7 +104,7 @@ "name": "Monthly Price Rating" }, "data_timestamp": { - "name": "Latest Data Available" + "name": "Price Data Expiration" }, "price_forecast": { "name": "Price Forecast"