Fix De Lijn 'tzinfo' error (#73502)

* Fix De Lijn component tzinfo error

This fix should update the issue "Error:'str' object has no attribute 'tzinfo'" (issue #67455)

* fix Black and isort errors

fixing errors from Black and isort CI validation

* Fix black and flake8 issues

Fixing black and flake8 issues to pass CI
pull/71867/head
Bram Goolaerts 2022-06-15 10:33:53 +02:00 committed by GitHub
parent a77ea1c390
commit 17eb8c95dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -1,6 +1,7 @@
"""Support for De Lijn (Flemish public transport) information."""
from __future__ import annotations
from datetime import datetime
import logging
from pydelijn.api import Passages
@ -111,7 +112,9 @@ class DeLijnPublicTransportSensor(SensorEntity):
first = self.line.passages[0]
if (first_passage := first["due_at_realtime"]) is None:
first_passage = first["due_at_schedule"]
self._attr_native_value = first_passage
self._attr_native_value = datetime.strptime(
first_passage, "%Y-%m-%dT%H:%M:%S%z"
)
for key in AUTO_ATTRIBUTES:
self._attr_extra_state_attributes[key] = first[key]