Skip to content

Commit

Permalink
fix for 2024.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Fischelsberger committed Apr 14, 2024
1 parent 84695ef commit 051d41a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions custom_components/car_wash/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.components.weather import (
ATTR_FORECAST,
ATTR_FORECAST_CONDITION,
ATTR_FORECAST_PRECIPITATION,
ATTR_FORECAST_TEMP,
Expand Down Expand Up @@ -141,7 +140,9 @@ def sensor_startup(event):
def _temp2c(temperature: Optional[float], temperature_unit: str) -> Optional[float]:
"""Convert weather temperature to Celsius degree."""
if temperature is not None and temperature_unit != UnitOfTemperature.CELSIUS:
temperature = TemperatureConverter.convert(temperature, temperature_unit, UnitOfTemperature.CELSIUS)
temperature = TemperatureConverter.convert(
temperature, temperature_unit, UnitOfTemperature.CELSIUS
)
return temperature

# pylint: disable=too-many-branches,too-many-statements
Expand All @@ -157,7 +158,15 @@ async def async_update(self):
tmpu = self.hass.config.units.temperature_unit
temp = wdata.attributes.get(ATTR_WEATHER_TEMPERATURE)
cond = wdata.state
forecast = wdata.attributes.get(ATTR_FORECAST)

daily_response = await self.hass.services.async_call(
"weather",
"get_forecasts",
{"entity_id": self._weather_entity, "type": "daily"},
blocking=True,
return_response=True,
)
forecast = daily_response[self._weather_entity]["forecast"]

if forecast is None:
self._attr_is_on = None
Expand Down Expand Up @@ -185,7 +194,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.utcfromtimestamp(fc_date / 1000)
datetime.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 051d41a

Please sign in to comment.