Skip to content

Add here_travel_time#24603

Merged
MartinHjelmare merged 47 commits into
home-assistant:devfrom
eifinger:here_travel_time
Sep 23, 2019
Merged

Add here_travel_time#24603
MartinHjelmare merged 47 commits into
home-assistant:devfrom
eifinger:here_travel_time

Conversation

@eifinger
Copy link
Copy Markdown
Contributor

@eifinger eifinger commented Jun 18, 2019

Description:

This PR adds here_travel_time as a new component. It is based on the code of google_travel_time but uses the here api.

Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#9648

Example entry for configuration.yaml (if applicable):

sensor:
  - platform: here_travel_time
    app_id: "YOUR_APP_ID"
    app_code: "YOUR_APP_CODE"
    origin_latitude: "51.222975"
    origin_longitude: "9.267577"
    destination_latitude: "51.257430"
    destination_longitude: "9.335892"

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly. Update and include derived files by running python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
@eifinger
Copy link
Copy Markdown
Contributor Author

eifinger commented Jul 3, 2019

Hi, thanks for taking the time and for giving me feedback. I'm on vacation this week and will get back to you next Monday.

Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
@eifinger
Copy link
Copy Markdown
Contributor Author

eifinger commented Jul 7, 2019

I implemented the requested changes. While doing so I looked at the architecture discussion you linked and the other travel_time integrations and I too see a need/benefit for a travel time component. Lots of duplicate code and different naming conventions for the same stuff.

I tried to follow the Waze implementation in order to have a common code base which can be refactored in the future.

I would prefer to do this refactoring (creating a travel_time component) in a follow up PR as this will need more discussions and will impact more than one integration.

@ljmerza
Copy link
Copy Markdown
Contributor

ljmerza commented Jul 9, 2019

You'll probably need to add tests to get this merged.

@eifinger
Copy link
Copy Markdown
Contributor Author

eifinger commented Jul 9, 2019

How would these tests look like / what should be tested?
I could not find any tests for google_travel_time or waze_travel_time as a reference.

@MartinHjelmare
Copy link
Copy Markdown
Member

Tests are not required, although appreciated, for integrations that communicates with devices or services.

@eifinger
Copy link
Copy Markdown
Contributor Author

I am happy to provide them. Could you point me to a component test which you think might be a good starting point on how to do it properly?

And thank you for the code, reviews and comments. I am really learning a lot here!

Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
@MartinHjelmare
Copy link
Copy Markdown
Member

MartinHjelmare commented Jul 11, 2019

The manual alarm control panel has test that set up the component, via setup_component or async_setup_component, which sets up the platform, adds an entity and asserts the state of the entity by getting it from the core state machine. Update is forced by mocking time passed.

https://github.com/home-assistant/home-assistant/blob/78a5dc71ac34637d8216f759be04ccc79c9f7b56/tests/components/manual/test_alarm_control_panel.py#L203-L235

I/O, api calls, should be patched as needed.

@eifinger
Copy link
Copy Markdown
Contributor Author

I added the requested changes. Will work on tests after the weekend

@eifinger
Copy link
Copy Markdown
Contributor Author

I released the component as a custom_component under https://github.com/eifinger/here_travel_time to gather some user feedback and did indeed find some bugs and missing features. Until I implement them and the tests I will close this PR and later reopen it again.

@eifinger eifinger closed this Jul 18, 2019
@ljmerza
Copy link
Copy Markdown
Contributor

ljmerza commented Jul 18, 2019 via email

@eifinger
Copy link
Copy Markdown
Contributor Author

I got to the tests faster than I thought. Let me know what I can improve, thank you!

@eifinger
Copy link
Copy Markdown
Contributor Author

@eifinger eifinger reopened this Jul 22, 2019
Comment thread tests/components/here_travel_time/test_sensor.py Outdated
Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
Comment thread tests/components/here_travel_time/test_sensor.py Outdated
@MartinHjelmare MartinHjelmare added the second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. label Jul 24, 2019
Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
Comment thread homeassistant/components/here_travel_time/sensor.py
Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
@MartinHjelmare
Copy link
Copy Markdown
Member

Just the final comment left to resolve. Then we can merge! 🎉

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@MartinHjelmare
Copy link
Copy Markdown
Member

Thanks for the dedicated work!

Can be merged when build passes.

@eifinger
Copy link
Copy Markdown
Contributor Author

Thank you for all the time and explanations! I learned a lot!

@eifinger
Copy link
Copy Markdown
Contributor Author

@MartinHjelmare I thought the frontend would somehow parse/clean up the attribution message but it does not. The frontend shows the message as is with html tags. Is there anything I can do on the component side?

here_travel_time_attribution_test

@eifinger
Copy link
Copy Markdown
Contributor Author

I found another attribution source in Ottawa, CA.

"sourceAttribution": {
            "attribution": "With the support of <span class=\"company\"><a href=\"https://transit.api.here.com/r?appId=Mt1bOYh3m9uxE7r3wuUx&u=http://ottawa.ca/en/mobile-apps-and-open-data/open-data-terms-use\">OC Transpo</a></span>. All information is provided without warranty of any kind.",
            "supplier": [
                {
                    "title": "OC Transpo",
                    "href": "https://transit.api.here.com/r?appId=Mt1bOYh3m9uxE7r3wuUx&u=http://ottawa.ca/en/mobile-apps-and-open-data/open-data-terms-use",
                    "note": [
                        {
                            "type": "disclaimer",
                            "text": "<a href=\"https://transit.api.here.com/r?appId=Mt1bOYh3m9uxE7r3wuUx&u=http://ottawa.ca/en/mobile-apps-and-open-data/open-data-terms-use\">Includes content from OC Transpo: http://ottawa.ca/en/mobile-apps-and-open-data/open-data-terms-use</a>",
                            "href": "https://transit.api.here.com/r?appId=Mt1bOYh3m9uxE7r3wuUx&u=http://ottawa.ca/en/mobile-apps-and-open-data/open-data-terms-use",
                            "hrefText": "Includes content from OC Transpo: http://ottawa.ca/en/mobile-apps-and-open-data/open-data-terms-use"
                        }
                    ]
                }
            ]
        }

Following the link provided under href leads to a 404. So I figure this information is not curated correctly.

I will add another commit which builds the attribution (if present) according to the supplier/title attribute.

Comment thread homeassistant/components/here_travel_time/sensor.py Outdated
@MartinHjelmare MartinHjelmare merged commit 5c0fa35 into home-assistant:dev Sep 23, 2019
@balloob balloob mentioned this pull request Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants