-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add OASA Telematics greek public transport sensor component #22196
Conversation
@@ -0,0 +1 @@ | |||
"""The OASA Telematics component.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank line at end of file
Hi! |
Hi @bkbilly, thanks that's interesting! However, I use a different approach. I find it simpler (and more useful) to get the upcoming arrivals for a given bus stop, mimicking the way the real bus stop displays work. Nonetheless we could definitely add the actual bus coordinates as a different mode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please clarify what we mean with "due in" and "next arrival".
For more info on the API see: | ||
https://oasa-telematics-api.readthedocs.io/en/latest/ | ||
For more details about this platform, please refer to the documentation at | ||
https://home-assistant.io/components/sensor.oasa_telematics/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't include the url in the docstring anymore. Just keep the very first line.
REQUIREMENTS = ['oasatelematics==0.2'] | ||
_LOGGER = logging.getLogger(__name__) | ||
|
||
ATTR_STOP_ID = 'Stop ID' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
State attribute keys should be lowercase snakecase.
}) | ||
|
||
|
||
def setup_platform(hass, config, add_devices, discovery_info=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename add_devices
to add_entities
.
self._times = self.data.info | ||
self._name_data = self.data.name_data | ||
try: | ||
self._state = self._times[0][ATTR_DUE_IN] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of making the state minutes until departure, make it an absolute utc timestamp and set device_class
property to timestamp.
This will allow the user to select a relative time representation of the state in the frontend.
https://developers.home-assistant.io/docs/en/entity_sensor.html#available-device-classes
if self._times is not None: | ||
next_arrival = None | ||
if len(self._times) > 1: | ||
next_arrival = ('{} min'.format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does next arrival mean? What is arriving where?
next_arrival = ('{} min'.format( | ||
str(self._times[1][ATTR_DUE_IN]))) | ||
params.update({ | ||
ATTR_DUE_IN: str(self._times[0][ATTR_DUE_IN]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does due in mean?
I'm thinking we're interested in next departure time. I don't understand what we mean with the other terms here, next arrival and due in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we use "due in" for state already. We shouldn't duplicate state in state attributes.
@staticmethod | ||
def empty_name_data(): | ||
"""Object returned when no stop/route name data are found.""" | ||
return [{ATTR_STOP_NAME: 'n/a', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of setting 'n/a'
, don't include these attributes in the state attributes at all if not known. If state isn't known we should set state to None
.
if route: | ||
return route[0].get('route_departure_eng') | ||
except TypeError: | ||
_LOGGER.debug("Cannot get route name from OASA API") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be a warning at least. How frequently could this occur?
@MartinHjelmare This sensor fetches the next bus arrival (in minutes) of a given bus line to a given bus stop. The estimated arrival time is what we poll the api for, but I agree that
|
Isn't departure more interesting than arrival, if this will be used to know what bus to catch? I'm thinking we could replace arrival with departure. But I'll leave this up to you. Thanks for clarifying the context. |
@property | ||
def unit_of_measurement(self): | ||
"""Return the unit this state is expressed in.""" | ||
return 'ISO8601' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The timestamp sensor device class doesn't use unit of measurement.
|
||
for result in results: | ||
arrival_min = int(result.get('btime2')) | ||
if arrival_min is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arrival_min
can't be None
at this point. There would have been an error at the line above where we copy to int in that case.
Move the check up before copying to int.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Can be merged when the merge conflict is solved and the build passes. |
Thanks for the feedback @MartinHjelmare |
Description:
Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#8978
Example entry for
configuration.yaml
(if applicable):Checklist:
tox
. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.