Skip to content

Commit

Permalink
fixed minor typos, added check of presence
Browse files Browse the repository at this point in the history
  • Loading branch information
Fischelsberger committed Apr 18, 2024
1 parent 0a952f3 commit 3322851
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions custom_components/car_wash/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
ATTR_FORECAST_TEMP_LOW,
ATTR_FORECAST_TIME,
ATTR_WEATHER_TEMPERATURE,
DOMAIN as WEATHER_DOMAIN,
SERVICE_GET_FORECASTS,
)
from homeassistant.const import (
CONF_NAME,
Expand All @@ -37,9 +39,6 @@
from homeassistant.util import dt as dt_util
from homeassistant.util.unit_conversion import TemperatureConverter

from homeassistant.components.weather import DOMAIN as WEATHER_DOMAIN
from homeassistant.components.weather import SERVICE_GET_FORECASTS

from .const import (
BAD_CONDITIONS,
CONF_DAYS,
Expand Down Expand Up @@ -169,7 +168,15 @@ async def async_update(self):
blocking=True,
return_response=True,
)
forecast = daily_response[self._weather_entity]["forecast"]
if not (isinstance(daily_response, dict)):
self._attr_is_on = None
raise HomeAssistantError("daily_response is empty.")
if (len(daily_response) == 0) or (
"forecast" in daily_response[self._weather_entity]
):
forecast = daily_response[self._weather_entity]["forecast"]
else:
forecast = None

if forecast is None:
self._attr_is_on = None
Expand Down Expand Up @@ -197,7 +204,7 @@ async def async_update(self):
fc_date = fcast.get(ATTR_FORECAST_TIME)
if isinstance(fc_date, int):
fc_date = dt_util.as_local(
datetime.datetime.fromtimestamp(fc_date, tz=datetime.timezone.utc)
datetime.fromtimestamp(fc_date, tz=datetime.timezone.utc)
).isoformat()
elif isinstance(fc_date, datetime):
fc_date = dt_util.as_local(fc_date).isoformat()
Expand Down

0 comments on commit 3322851

Please sign in to comment.