mirror of
https://github.com/jpawlowski/hass.tibber_prices.git
synced 2026-03-30 05:13:40 +00:00
fix
This commit is contained in:
parent
71b81a9812
commit
1f8158ecea
6 changed files with 34 additions and 30 deletions
|
|
@ -123,26 +123,28 @@ class TibberPricesBinarySensor(TibberPricesEntity, BinarySensorEntity):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def _best_price_state(self) -> bool | None:
|
def _best_price_state(self) -> bool | None:
|
||||||
"""Return True if current price is within +flex% of the day's minimum price."""
|
"""Return True if the current time is within a best price period."""
|
||||||
price_data = self._get_current_price_data()
|
if not self.coordinator.data:
|
||||||
if not price_data:
|
|
||||||
return None
|
return None
|
||||||
prices, current_price = price_data
|
attrs = self._get_price_intervals_attributes(reverse_sort=False)
|
||||||
min_price = min(prices)
|
if not attrs or "interval_start" not in attrs or "interval_end" not in attrs:
|
||||||
flex = self._get_flex_option(CONF_BEST_PRICE_FLEX, DEFAULT_BEST_PRICE_FLEX)
|
return None
|
||||||
threshold = min_price * (1 + flex)
|
now = dt_util.now()
|
||||||
return current_price <= threshold
|
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:
|
def _peak_price_state(self) -> bool | None:
|
||||||
"""Return True if current price is within -flex% of the day's maximum price."""
|
"""Return True if the current time is within a peak price period."""
|
||||||
price_data = self._get_current_price_data()
|
if not self.coordinator.data:
|
||||||
if not price_data:
|
|
||||||
return None
|
return None
|
||||||
prices, current_price = price_data
|
attrs = self._get_price_intervals_attributes(reverse_sort=True)
|
||||||
max_price = max(prices)
|
if not attrs or "interval_start" not in attrs or "interval_end" not in attrs:
|
||||||
flex = self._get_flex_option(CONF_PEAK_PRICE_FLEX, DEFAULT_PEAK_PRICE_FLEX)
|
return None
|
||||||
threshold = max_price * (1 - flex)
|
now = dt_util.now()
|
||||||
return current_price >= threshold
|
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:
|
def _tomorrow_data_available_state(self) -> bool | None:
|
||||||
"""Return True if tomorrow's data is fully available, False if not, None if unknown."""
|
"""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"]
|
price_info = self.coordinator.data["data"]["viewer"]["homes"][0]["currentSubscription"]["priceInfo"]
|
||||||
tomorrow_prices = price_info.get("tomorrow", [])
|
tomorrow_prices = price_info.get("tomorrow", [])
|
||||||
interval_count = len(tomorrow_prices)
|
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:
|
def _get_tomorrow_data_available_attributes(self) -> dict | None:
|
||||||
"""Return attributes for tomorrow_data_available binary sensor."""
|
"""Return attributes for tomorrow_data_available binary sensor."""
|
||||||
|
|
|
||||||
|
|
@ -97,10 +97,9 @@
|
||||||
"usage_tips": "Ein positiver Prozentsatz bedeutet, dass die Preise dieses Monats überdurchschnittlich sind, negativ bedeutet unterdurchschnittlich"
|
"usage_tips": "Ein positiver Prozentsatz bedeutet, dass die Preise dieses Monats überdurchschnittlich sind, negativ bedeutet unterdurchschnittlich"
|
||||||
},
|
},
|
||||||
"data_timestamp": {
|
"data_timestamp": {
|
||||||
"name": "Zeitstempel der neuesten Daten",
|
"name": "Ablauf der Preisdaten",
|
||||||
"description": "Wann die neuesten Preisdaten empfangen wurden",
|
"description": "Zeitstempel des letzten verfügbaren Preisintervalls",
|
||||||
"long_description": "Zeigt den Zeitstempel des letzten Preisaktualisierung von Tibber",
|
"long_description": "Zeigt den Zeitstempel des letzten verfügbaren Preisintervalls von deinem Tibber-Abonnement an"
|
||||||
"usage_tips": "Nutze dies, um zu überprüfen, wann die Preisinformationen zuletzt aktualisiert wurden"
|
|
||||||
},
|
},
|
||||||
"price_forecast": {
|
"price_forecast": {
|
||||||
"name": "Preisprognose",
|
"name": "Preisprognose",
|
||||||
|
|
@ -135,4 +134,4 @@
|
||||||
"usage_tips": "Nutze dies, um den Verbindungsstatus zur Tibber API zu überwachen"
|
"usage_tips": "Nutze dies, um den Verbindungsstatus zur Tibber API zu überwachen"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -97,10 +97,9 @@
|
||||||
"usage_tips": "A positive percentage means this month's prices are above average, negative means below average"
|
"usage_tips": "A positive percentage means this month's prices are above average, negative means below average"
|
||||||
},
|
},
|
||||||
"data_timestamp": {
|
"data_timestamp": {
|
||||||
"name": "Latest Data Timestamp",
|
"name": "Price Data Expiration",
|
||||||
"description": "When the latest price data was received",
|
"description": "Timestamp of the latest available price data interval",
|
||||||
"long_description": "Shows the timestamp of the most recent price data update from Tibber",
|
"long_description": "Shows the timestamp of the latest available price data interval from your Tibber subscription"
|
||||||
"usage_tips": "Use this to check when price information was last updated"
|
|
||||||
},
|
},
|
||||||
"price_forecast": {
|
"price_forecast": {
|
||||||
"name": "Price Forecast",
|
"name": "Price Forecast",
|
||||||
|
|
@ -135,4 +134,4 @@
|
||||||
"usage_tips": "Use this to monitor the connection status to the Tibber API"
|
"usage_tips": "Use this to monitor the connection status to the Tibber API"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,7 @@ DIAGNOSTIC_SENSORS = (
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key="data_timestamp",
|
key="data_timestamp",
|
||||||
translation_key="data_timestamp",
|
translation_key="data_timestamp",
|
||||||
name="Latest Data Available",
|
name="Data Expiration",
|
||||||
icon="mdi:clock-check",
|
icon="mdi:clock-check",
|
||||||
device_class=SensorDeviceClass.TIMESTAMP,
|
device_class=SensorDeviceClass.TIMESTAMP,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@
|
||||||
"name": "Monatliche Preisbewertung"
|
"name": "Monatliche Preisbewertung"
|
||||||
},
|
},
|
||||||
"data_timestamp": {
|
"data_timestamp": {
|
||||||
"name": "Zeitstempel der neuesten Daten"
|
"name": "Ablauf der Preisdaten"
|
||||||
},
|
},
|
||||||
"next_interval_price": {
|
"next_interval_price": {
|
||||||
"name": "Strompreis nächstes Intervall"
|
"name": "Strompreis nächstes Intervall"
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@
|
||||||
"name": "Monthly Price Rating"
|
"name": "Monthly Price Rating"
|
||||||
},
|
},
|
||||||
"data_timestamp": {
|
"data_timestamp": {
|
||||||
"name": "Latest Data Available"
|
"name": "Price Data Expiration"
|
||||||
},
|
},
|
||||||
"price_forecast": {
|
"price_forecast": {
|
||||||
"name": "Price Forecast"
|
"name": "Price Forecast"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue