This commit is contained in:
Home Assistant Version Control
2026-08-20 15:12:43 +00:00
parent 33669f8f1e
commit 6644b9e4a8
19 changed files with 285 additions and 110 deletions
@@ -26,8 +26,8 @@ class Forecast(UnicodeMixin):
self.json = data
self._alerts = []
for alertJSON in self.json.get("alerts", []):
self._alerts.append(Alert(alertJSON))
for alert_json in self.json.get("alerts", []):
self._alerts.append(Alert(alert_json))
def update(self):
"""Update the forecast data by making a new request to the same URL."""
@@ -135,24 +135,24 @@ class PirateWeatherFlagsBlock(UnicodeMixin):
class PirateWeatherDataPoint(UnicodeMixin):
"""Represent a single data point in a weather forecast, such as an hourly or daily data point."""
def __init__(self, d={}):
def __init__(self, d=None):
"""Initialize the data point with timestamp and weather information."""
self.d = d
self.d = d or {}
try:
self.time = datetime.datetime.fromtimestamp(int(d["time"]))
self.utime = d["time"]
self.time = datetime.datetime.fromtimestamp(int(self.d["time"]))
self.utime = self.d["time"]
except KeyError:
pass
try:
sr_time = int(d["sunriseTime"])
sr_time = int(self.d["sunriseTime"])
self.sunriseTime = datetime.datetime.fromtimestamp(sr_time)
except KeyError:
self.sunriseTime = None
try:
ss_time = int(d["sunsetTime"])
ss_time = int(self.d["sunsetTime"])
self.sunsetTime = datetime.datetime.fromtimestamp(ss_time)
except KeyError:
self.sunsetTime = None