[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):
|
||||
"""Update device state."""
|
||||
self.data.get_data()
|
||||
next_time = datetime.strptime(
|
||||
self.data.state_bus['time'][0]['run'], "%H:%M")
|
||||
next_time = get_datetime(self.data.state_bus)
|
||||
self._state = next_time.isoformat()
|
||||
|
||||
|
||||
|
@ -99,8 +98,7 @@ class GttData:
|
|||
def get_data(self):
|
||||
"""Get the data from the api."""
|
||||
self.bus_list = self._pygtt.get_by_stop(self._stop)
|
||||
self.bus_list.sort(key=lambda b:
|
||||
datetime.strptime(b['time'][0]['run'], "%H:%M"))
|
||||
self.bus_list.sort(key=get_datetime)
|
||||
|
||||
if self._bus_name is not None:
|
||||
self.state_bus = self.get_bus_by_name()
|
||||
|
@ -113,3 +111,13 @@ class GttData:
|
|||
for bus in self.bus_list:
|
||||
if bus['bus_name'] == self._bus_name:
|
||||
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