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

Update Fitbit integration to allow UI based configuration #100897

Merged
merged 23 commits into from Sep 30, 2023

Conversation

allenporter
Copy link
Contributor

@allenporter allenporter commented Sep 26, 2023

Proposed change

Update Fitbit integration to allow UI based configuration entries.

Given the existing features, this is a larger PR than I was hoping. This could be split into smaller PRs if we didn't have to worry about backwards compatibility with existing configuration. Open to suggestions for how to make this smaller.

The authentication system has been reworked to use application credentials. See the Fitbit Developer Guide: Authorization for details on the authentication.

The old approach was configured with these steps:

  • Add the platform sensor configuration in yaml
  • From the UI, enter the configurator flow. The step was to manually enter credentials into a fitbit.conf file.
  • The UI then redirects you to fitbit to authorize, and the integration refreshes the credentials in fitbit.conf.

This change will import credentials into application credentials if they already exist.

The existing settings for which entities to add, clock format, and units are imported automatically. For new integrations, the entities to include are now automatically determined based on the allowed scopes enabled by the user.

TODO: Link to documentation

This is pulled out of a larger overhaul to modernize the fitbit integration and make it configurable from the UI and following current design standards, similar to previous approach on Google calendar :

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 Black (black --fast 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.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

homeassistant/components/fitbit/strings.json Outdated Show resolved Hide resolved
homeassistant/components/fitbit/strings.json Outdated Show resolved Hide resolved
homeassistant/components/fitbit/api.py Show resolved Hide resolved
@allenporter allenporter marked this pull request as draft September 26, 2023 14:18
homeassistant/components/fitbit/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/fitbit/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/fitbit/const.py Outdated Show resolved Hide resolved
homeassistant/components/fitbit/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/fitbit/sensor.py Outdated Show resolved Hide resolved
tests/components/fitbit/test_init.py Show resolved Hide resolved
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
@allenporter allenporter marked this pull request as draft September 27, 2023 14:34
Copy link
Contributor Author

@allenporter allenporter left a comment

Choose a reason for hiding this comment

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

Thanks for the review. I improved test coverage to try to make some of the checks happier as well.

Now this PR is looking for additional input on the import config flow to make sure we're coverage the cases right. Reviewers, check out the config flow tests to see what the cases look like.

@allenporter allenporter marked this pull request as ready for review September 27, 2023 14:48
homeassistant/components/fitbit/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/fitbit/application_credentials.py Outdated Show resolved Hide resolved
homeassistant/components/fitbit/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/fitbit/strings.json Outdated Show resolved Hide resolved
homeassistant/components/fitbit/strings.json Outdated Show resolved Hide resolved
homeassistant/components/fitbit/strings.json Outdated Show resolved Hide resolved
homeassistant/components/fitbit/sensor.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft September 29, 2023 06:14
@allenporter allenporter marked this pull request as ready for review September 29, 2023 14:20
@allenporter
Copy link
Contributor Author

There is a codecov check that appears incorrect. deprecated_yaml_import_issue_cannot_connect is definitely covered by tests that assert on the issue and reason. (I don't want to force push, though, to make review harder)

@MartinHjelmare MartinHjelmare marked this pull request as draft September 30, 2023 06:09
@allenporter allenporter marked this pull request as ready for review September 30, 2023 16:35
Copy link
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.

Nice!

@allenporter allenporter merged commit bd2fee2 into home-assistant:dev Sep 30, 2023
21 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Oct 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants