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

Add Unit System Option For Fitbit #11817

Merged
merged 3 commits into from Feb 28, 2018
Merged

Add Unit System Option For Fitbit #11817

merged 3 commits into from Feb 28, 2018

Conversation

bertbert72
Copy link
Contributor

Description:

Allow overriding of the units to be used for the Fitbit sensor, e.g. allowing metric units to be used on an en_GB system.

Related issue (if applicable): fixes # n/a

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#4469

Example entry for configuration.yaml (if applicable):

sensor:
  - platform: fitbit
    clock_format: 12H
    unit_system: metric
    monitored_resources:
      - "body/weight"

Checklist:

  • The code change is tested and works locally.

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

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

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

authd_client.system = 'en_US'
unit_system = config.get(CONF_UNIT_SYSTEM)
if unit_system == 'default':
authd_client.system = authd_client.user_profile_get()["user"]["locale"]

Choose a reason for hiding this comment

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

line too long (83 > 79 characters)

vol.In(['12H', '24H'])
vol.In(['12H', '24H']),
vol.Optional(CONF_UNIT_SYSTEM, default='default'):
vol.In(['en_GB', 'en_US', 'metric','default'])

Choose a reason for hiding this comment

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

missing whitespace after ','

@@ -34,6 +34,7 @@

CONF_MONITORED_RESOURCES = 'monitored_resources'
CONF_CLOCK_FORMAT = 'clock_format'
CONF_UNIT_SYSTEM = 'unit_system'
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 already defined in const.py. Please import that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, done

@tinloaf
Copy link
Contributor

tinloaf commented Feb 13, 2018

It's somehow weird that en_US and en_GB are special. No other locale is handled specially… is that a limitation of the fitbit API? I couldn't find anything relating to that at https://python-fitbit.readthedocs.io/en/latest/ … In fact, they seem to be using en_UK instead of metric (see https://github.com/orcasgit/python-fitbit/blob/master/fitbit/api.py#L187 )

@bertbert72
Copy link
Contributor Author

Yes, see here:

https://dev.fitbit.com/build/reference/web-api/basics/#units

Options are

en_US => US
en_GB => UK
none of the above or not provided => METRIC

So anything other than en_GB or en_US becomes metric. If they are using en_UK then that'll translate to metric in the API.

Copy link
Contributor

@tinloaf tinloaf left a comment

Choose a reason for hiding this comment

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

Okay, looking good! 👍

@balloob
Copy link
Member

balloob commented Feb 28, 2018

@tinloaf feel free to merge when you approve 👍

@balloob balloob merged commit 44cad7d into home-assistant:dev Feb 28, 2018
@bertbert72 bertbert72 deleted the patch-1 branch March 1, 2018 06:12
@balloob balloob mentioned this pull request Mar 9, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Jul 26, 2018
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

6 participants