Skip to content
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

Migrate meteoalarm integration to config flow #124290

Draft
wants to merge 18 commits into
base: dev
Choose a base branch
from

Conversation

WebSpider
Copy link
Contributor

@WebSpider WebSpider commented Aug 20, 2024

Proposed change

Add config flow to meteoalarm integration

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

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.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @rolfberkenbosch, mind taking a look at this pull request as it has been labeled with an integration (meteoalarm) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of meteoalarm can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign meteoalarm Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@WebSpider WebSpider marked this pull request as draft August 20, 2024 11:19
@WebSpider
Copy link
Contributor Author

Still working on local tests

Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

Config flows should be 100% unit tested, so please add unit tests :)

homeassistant/components/meteoalarm/binary_sensor.py Outdated Show resolved Hide resolved
Comment on lines 96 to 104
try:
api = Meteoalert(country, province, language)
api = Meteoalert(
entry.data[CONF_COUNTRY],
entry.data[CONF_PROVINCE],
entry.data[CONF_LANGUAGE],
)
except KeyError:
_LOGGER.error("Wrong country digits or province name")
LOGGER.error("Wrong country digits or province name")
return
Copy link
Member

Choose a reason for hiding this comment

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

This should be moved to __init__.py. We should store that in entry.runtime_data (please make sure you extend the typing of ConfigEntry for type checking

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joostlek Thanks for looking at this so quick.

This is my first config-flow conversion.
I've been having some trouble finding documentation for types such as ConfigEntry, ConfigFlowResult, etc. Is there anything available that you know of, besides using the source?

Copy link
Member

Choose a reason for hiding this comment

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

The source and all the other integrations out there. Reworking the docs is something on my list

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be moved to __init__.py. We should store that in entry.runtime_data (please make sure you extend the typing of ConfigEntry for type checking

I am struggling to understand what you mean here. Do you have an example?

Copy link
Member

Choose a reason for hiding this comment

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

AirGradient has an example, type MeteoAlarmConfigEntry = ConfigEntry[...]

homeassistant/components/meteoalarm/binary_sensor.py Outdated Show resolved Hide resolved
homeassistant/components/meteoalarm/binary_sensor.py Outdated Show resolved Hide resolved
homeassistant/components/meteoalarm/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/meteoalarm/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/meteoalarm/config_flow.py Outdated Show resolved Hide resolved
@joostlek
Copy link
Member

Oh lol, it was ready for review so I already gave it a shot :)

@WebSpider WebSpider marked this pull request as ready for review August 20, 2024 14:32
@WebSpider
Copy link
Contributor Author

Remaining: Test config import

Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

We're missing the tests for the config flow. It should be 100% unit tested

homeassistant/components/meteoalarm/binary_sensor.py Outdated Show resolved Hide resolved
homeassistant/components/meteoalarm/binary_sensor.py Outdated Show resolved Hide resolved
Comment on lines 57 to 58
LOGGER.error("Wrong country digits or province name")
errors["base"] = "wrong_country_or_province"
Copy link
Member

Choose a reason for hiding this comment

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

Country can't be wrong now right?

Is there a predefined list of provinces per country? Maybe it's worth introducing an extra step to select the province so people can't mess it up (as in, if we can avoid people looking up what to fill in and make mistakes, that's always nice)

Copy link
Contributor

Choose a reason for hiding this comment

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

I had a look some time ago into this integration and it simply isn't possible to fetch the list dynamically at runtime.

As far as I'm aware, there's also no KeyError being throw in the library to know that the province provided is incorrect. When the wrong province is given, it will simply return no alerts (since it will never match your wrong province.)

The list of countries is provided on their https://feeds.meteoalarm.org/ page only, so hardcoding is the only solution here (no html parsing allowed). The list of provinces is also available in a Google docs json file available through their redistribution hub. That's a 30MB file with shapes included. I think hardcoding is also the only solution here, but note that some countries do have a lot of provinces.

Copy link
Member

Choose a reason for hiding this comment

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

This is a good one to check with others. I think it's nice to make it foolproof, because you also explain it won't work otherwise.

But that dict should ideally live in the library

homeassistant/components/meteoalarm/config_flow.py Outdated Show resolved Hide resolved
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant home-assistant bot marked this pull request as draft August 24, 2024 06:29
Copy link

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.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added the stale label Oct 23, 2024
@WebSpider
Copy link
Contributor Author

Unstale pls

@github-actions github-actions bot removed the stale label Oct 23, 2024
Copy link

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.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added the stale label Dec 30, 2024
@WebSpider
Copy link
Contributor Author

/unstale

@github-actions github-actions bot removed the stale label Dec 30, 2024
@WebSpider
Copy link
Contributor Author

Apologies for the lack of updates in this issue. I have been putting my time in developing a custom integration, while gaining experience on how to do this properly. Going forward with this integration now. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants