Add travel_time integration#28716
Conversation
|
I would like to put https://github.com/home-assistant/home-assistant/pull/28716/files#diff-2bf8b028fb7894b26af233d297725765L96-L114 into |
|
@robbiet480 you are codeowner for |
f4defe0 to
05b0f40
Compare
|
Working on the integration for The usecase would be to give me the weather forecast for the current location of a device_tracker each morning. Or combine it with my calendar and send me the forecast for the location I have to travel to for work tomorrow. Therefore I would rather rename the function to |
|
I did have the idea to remove the magic of getting the coordinates from a different entity and provide an additonal option But then again the user would have to know the different ways to extract coordinates from a sensor, device_tracker, zone and so on. Just now writing this I am thinking of a combined version: Introducing a new jinja2 function input_select:
here_destination_preset:
options:
- zone.home
- zone.office
- zone.somewheredefault
travel_time:
- platform: here_travel_time
app_id: my_app_id
app_code: my_app_code
origin_template: {{ get_coordinates_from_entity(device_tracker.myphone) }}
destination_template: {{ get_coordinates_from_entity(input_select.here_destination_preset) }} |
|
very nice indeed, and just as I was building myself in templates see: https://community.home-assistant.io/t/waze-travel-time-update/50955/286?u=mariusthvdb I've made the input_select pick either a zone or a device_tracker, and have the origin and destination sensor sortout the lat/long please continue, this would be very welcome indeed. also, shouldn't this be with quoted entities: to be compliant with regular Jinja templating? |
05b0f40 to
7ae5373
Compare
| @property | ||
| def state(self) -> Optional[str]: | ||
| """Return the state of the travel_time entity.""" | ||
| return None |
There was a problem hiding this comment.
We should always have the base class define the state property. It should return one of the other properties.
|
|
||
| SCAN_INTERVAL = timedelta(minutes=5) | ||
|
|
||
| PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({}, extra=vol.ALLOW_EXTRA) |
There was a problem hiding this comment.
We should specify a standardized schema that platforms have to follow to specify source and target location?
There was a problem hiding this comment.
-
For that I would like to have Add template extension coordinates #30019 merged first.
-
Moreover the current travel_time integrations provide support for at least coordinates. Waze and Google allow names and Google allows for Google Place Ids as well.
All integrations allow to supply entity_ids like device_trackers etc.Google and Waze both only have
destinationandoriginwhich can hold everything.For HERE we introduced separate
origin_latitude,origin_entity_id, and so on. The
discussion can be found here: https://github.com/home-assistant/home-
assistant/pull/24603#discussion_r311280860So I am not sure what should be standard given all these options.
-
Given the above I implemented the check that exactly one method is used for
here_travel_timein the following way: https://github.com/home-assistant/home-assistant/blob/7ae537304e8f8bc548c1f67b997b06fe07bb6da8/homeassistant/components/here_travel_time/travel_time.py#L83-L90 but do not know how to put that in a base schema. All the ways I tried lead to "schema cannot be extended because it is not adict"
There was a problem hiding this comment.
#30019 can be added later.
It's up to the travel time integration to provide a way to specify the origin and destination. Platforms just need to provide travel time.
The standard should be to accept one of those options. Like you did with here_travel_time.
There was a problem hiding this comment.
So this means no standard platform schema in travel_time. Did I understand you correct?
I am not sure whether your initial comment on this was a question whether we should do so or your opinion that we should.
There was a problem hiding this comment.
No I think we should have a standard platform schema and standardize how people define origin and destination. If we don't do that, then why standardize anything at all ?
There was a problem hiding this comment.
I implemented a standard TRAVEL_TIME_SCHEMA.
It allows origin and destination to either be defined by a name or a combination of latitude and longitude.
Moreover each of them can be a template:
origin_latitude: 0.0
origin_longitude: {{ state_attr('device_tracker.paulus', 'longitude') }}
destination_name: Berlin| return None | ||
|
|
||
| @property | ||
| def duration_in_traffic(self) -> str: |
There was a problem hiding this comment.
Is this something that is always available ? Should we start with not having this
There was a problem hiding this comment.
Distance and destination_name are used by the travel_time card by @ljmerza.
Having both duration and duration_in_traffic enables certain usecases without having to create two sensors. E.g. alert me when the current duration_in_traffic is more than 30% of the normal duration.
waze_travel_time is the only integration to currently not support duration_in_traffic.
balloob
left a comment
There was a problem hiding this comment.
Please remove the migration from here_travel_time to a platform for travel_time from this PR. Instead, add a demo platform. Also make sure to include tests.
ae5ac53 to
d7b24fe
Compare
Codecov Report
@@ Coverage Diff @@
## dev #28716 +/- ##
======================================
Coverage ? 94.67%
======================================
Files ? 765
Lines ? 55352
Branches ? 0
======================================
Hits ? 52407
Misses ? 2945
Partials ? 0
Continue to review full report at Codecov.
|
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
Still open |
3407406 to
5dce233
Compare
| return await hass.data[DOMAIN].async_unload_entry(entry) | ||
|
|
||
|
|
||
| class TravelTimeEntity(Entity): |
There was a problem hiding this comment.
I've been thinking about this more and I think that we should have platforms implement entities. Shouldn't it just be services that take in a start, end and options and return a measurement which then is represented by an entity.
There was a problem hiding this comment.
The idea behind this was the other way round. Define a clear set of properties a TravelTime Entity should have so they can be used in Lovelace cards, automations, appdaemon etc.
Currently all of the above look different for Google, Waze, Here....
For example:
Google has an attribute destination_addresses which is a list.
Waze has destination_address HERE has destination_name.
Additional thought was that the configuration options should be named the same.
There was a problem hiding this comment.
That would still work ? The travel_time integration defines thte entity and the exposed data, so it's the same. It just sources that data from a service object provided by integrations instead of having integrations provide the entity objects directly.
There was a problem hiding this comment.
Is there an existing platform/integration which does that already so I could have a look?
There was a problem hiding this comment.
Notification, but I don't like that implementation :(
I guess we can still use entities but just have each entity implement an abstract method that returns all info at once ?
I don't know. Maybe the existing approach is ok. 🤷♂ It just feels a little weird.
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
Breaking Change:
Description:
As discussed in #27237 and home-assistant/architecture#166 this PR adds a base
travel_timeintegration to use forwaze_travel_time,google_travel_timeandhere_travel_time.This allows for code deduplication and standards for attributes etc.
Related issue (if applicable): fixes N/A
Pull request with documentation for home-assistant.io (if applicable): TBD
Example entry for
configuration.yaml(if applicable):TBDChecklist:
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:
python3 -m script.hassfest.requirements_all.txtby runningpython3 -m script.gen_requirements_all..coveragerc.If the code does not interact with devices: