mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Fix timezone trafikverket_train (#62582)
* Bugfix trafikverket train * Change from pytz to hass function * Fix datetime in extra attributes * Fix time timezone * Reset changes extra attributes
This commit is contained in:
parent
0b8cf47613
commit
0e48a658f3
@ -14,6 +14,7 @@ from homeassistant.components.sensor import (
|
|||||||
from homeassistant.const import CONF_API_KEY, CONF_NAME, CONF_WEEKDAY, WEEKDAYS
|
from homeassistant.const import CONF_API_KEY, CONF_NAME, CONF_WEEKDAY, WEEKDAYS
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.util.dt import get_time_zone
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -129,12 +130,15 @@ class TrainSensor(SensorEntity):
|
|||||||
self._state = None
|
self._state = None
|
||||||
self._departure_state = None
|
self._departure_state = None
|
||||||
self._delay_in_minutes = None
|
self._delay_in_minutes = None
|
||||||
|
self._timezone = get_time_zone("Europe/Stockholm")
|
||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Retrieve latest state."""
|
"""Retrieve latest state."""
|
||||||
if self._time is not None:
|
if self._time is not None:
|
||||||
departure_day = next_departuredate(self._weekday)
|
departure_day = next_departuredate(self._weekday)
|
||||||
when = datetime.combine(departure_day, self._time)
|
when = datetime.combine(departure_day, self._time).astimezone(
|
||||||
|
self._timezone
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
self._state = await self._train_api.async_get_train_stop(
|
self._state = await self._train_api.async_get_train_stop(
|
||||||
self._from_station, self._to_station, when
|
self._from_station, self._to_station, when
|
||||||
@ -191,8 +195,8 @@ class TrainSensor(SensorEntity):
|
|||||||
"""Return the departure state."""
|
"""Return the departure state."""
|
||||||
if (state := self._state) is not None:
|
if (state := self._state) is not None:
|
||||||
if state.time_at_location is not None:
|
if state.time_at_location is not None:
|
||||||
return state.time_at_location
|
return state.time_at_location.astimezone(self._timezone)
|
||||||
if state.estimated_time_at_location is not None:
|
if state.estimated_time_at_location is not None:
|
||||||
return state.estimated_time_at_location
|
return state.estimated_time_at_location.astimezone(self._timezone)
|
||||||
return state.advertised_time_at_location
|
return state.advertised_time_at_location.astimezone(self._timezone)
|
||||||
return None
|
return None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user