mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Set GTFS icon by route type (#20876)
This commit is contained in:
parent
d16d14b648
commit
9db9a81793
@ -29,6 +29,16 @@ DEFAULT_NAME = 'GTFS Sensor'
|
|||||||
DEFAULT_PATH = 'gtfs'
|
DEFAULT_PATH = 'gtfs'
|
||||||
|
|
||||||
ICON = 'mdi:train'
|
ICON = 'mdi:train'
|
||||||
|
ICONS = {
|
||||||
|
0: 'mdi:tram',
|
||||||
|
1: 'mdi:subway',
|
||||||
|
2: 'mdi:train',
|
||||||
|
3: 'mdi:bus',
|
||||||
|
4: 'mdi:ferry',
|
||||||
|
5: 'mdi:train-variant',
|
||||||
|
6: 'mdi:gondola',
|
||||||
|
7: 'mdi:stairs',
|
||||||
|
}
|
||||||
|
|
||||||
TIME_FORMAT = '%Y-%m-%d %H:%M:%S'
|
TIME_FORMAT = '%Y-%m-%d %H:%M:%S'
|
||||||
|
|
||||||
@ -193,6 +203,7 @@ class GTFSDepartureSensor(Entity):
|
|||||||
self.destination = destination
|
self.destination = destination
|
||||||
self._offset = offset
|
self._offset = offset
|
||||||
self._custom_name = name
|
self._custom_name = name
|
||||||
|
self._icon = ICON
|
||||||
self._name = ''
|
self._name = ''
|
||||||
self._unit_of_measurement = 'min'
|
self._unit_of_measurement = 'min'
|
||||||
self._state = 0
|
self._state = 0
|
||||||
@ -223,7 +234,7 @@ class GTFSDepartureSensor(Entity):
|
|||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
"""Icon to use in the frontend, if any."""
|
"""Icon to use in the frontend, if any."""
|
||||||
return ICON
|
return self._icon
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest data from GTFS and update the states."""
|
"""Get the latest data from GTFS and update the states."""
|
||||||
@ -257,6 +268,8 @@ class GTFSDepartureSensor(Entity):
|
|||||||
self._attributes = {}
|
self._attributes = {}
|
||||||
self._attributes['offset'] = self._offset.seconds / 60
|
self._attributes['offset'] = self._offset.seconds / 60
|
||||||
|
|
||||||
|
self._icon = ICONS.get(route.route_type, ICON)
|
||||||
|
|
||||||
def dict_for_table(resource):
|
def dict_for_table(resource):
|
||||||
"""Return a dict for the SQLAlchemy resource given."""
|
"""Return a dict for the SQLAlchemy resource given."""
|
||||||
return dict((col, getattr(resource, col))
|
return dict((col, getattr(resource, col))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user