[FIX] Time reporting incorrect in sensor.gtt (#20362)
* quick fix * remove print statement * fixes * remove lambda * added pylint disable * should be fine now
This commit is contained in:
parent
0300ef2040
commit
971d933140
1 changed files with 12 additions and 4 deletions
|
@ -79,8 +79,7 @@ class GttSensor(Entity):
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update device state."""
|
"""Update device state."""
|
||||||
self.data.get_data()
|
self.data.get_data()
|
||||||
next_time = datetime.strptime(
|
next_time = get_datetime(self.data.state_bus)
|
||||||
self.data.state_bus['time'][0]['run'], "%H:%M")
|
|
||||||
self._state = next_time.isoformat()
|
self._state = next_time.isoformat()
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,8 +98,7 @@ class GttData:
|
||||||
def get_data(self):
|
def get_data(self):
|
||||||
"""Get the data from the api."""
|
"""Get the data from the api."""
|
||||||
self.bus_list = self._pygtt.get_by_stop(self._stop)
|
self.bus_list = self._pygtt.get_by_stop(self._stop)
|
||||||
self.bus_list.sort(key=lambda b:
|
self.bus_list.sort(key=get_datetime)
|
||||||
datetime.strptime(b['time'][0]['run'], "%H:%M"))
|
|
||||||
|
|
||||||
if self._bus_name is not None:
|
if self._bus_name is not None:
|
||||||
self.state_bus = self.get_bus_by_name()
|
self.state_bus = self.get_bus_by_name()
|
||||||
|
@ -113,3 +111,13 @@ class GttData:
|
||||||
for bus in self.bus_list:
|
for bus in self.bus_list:
|
||||||
if bus['bus_name'] == self._bus_name:
|
if bus['bus_name'] == self._bus_name:
|
||||||
return bus
|
return bus
|
||||||
|
|
||||||
|
|
||||||
|
def get_datetime(bus):
|
||||||
|
"""Get the datetime from a bus."""
|
||||||
|
bustime = datetime.strptime(bus['time'][0]['run'], "%H:%M")
|
||||||
|
now = datetime.now()
|
||||||
|
bustime = bustime.replace(year=now.year, month=now.month, day=now.day)
|
||||||
|
if bustime < now:
|
||||||
|
bustime = bustime + timedelta(days=1)
|
||||||
|
return bustime
|
||||||
|
|
Loading…
Add table
Reference in a new issue