Skip to content

show battery_level as a percent vs a decimal#18328

Merged
amelchio merged 4 commits intohome-assistant:devfrom
chriskacerguis:wireless-tag-battery-fix
Nov 10, 2018
Merged

show battery_level as a percent vs a decimal#18328
amelchio merged 4 commits intohome-assistant:devfrom
chriskacerguis:wireless-tag-battery-fix

Conversation

@chriskacerguis
Copy link
Copy Markdown
Contributor

@chriskacerguis chriskacerguis commented Nov 8, 2018

Description:

Currently the battery level for the WirelessTag component is returned as a decimal (e.g. 0.79 for 79%). This causes issues when these sensors are exposed via HomeKit (as HomeKit interoperates 0.79 as 0.79%), this fixes that issue properly return the battery_level as a percent.

Note: This is my first time working with Python, so please be gentile ;)

Related issue (if applicable): N/A

Breaking change note

The WirelessTag battery_level attribute is now reported as percent (i.e. 79, not 0.79).

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.

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

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

If the code does not interact with devices: N/A

@ghost ghost added the in progress label Nov 8, 2018
"""Return the state attributes."""
return {
ATTR_BATTERY_LEVEL: self._tag.battery_remaining,
ATTR_BATTERY_LEVEL: '{:.0%}'.format(self._tag.battery_remaining),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will misbehave if other devices have a value between 1 and 100 for battery_remaining. Do all devices report battery_remaining as a decimal between 0 and 1?

Copy link
Copy Markdown
Contributor Author

@chriskacerguis chriskacerguis Nov 9, 2018

Choose a reason for hiding this comment

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

When you say "other devices" do you mean outside of wireless tag devices? I can't comment what every one does, however, from what I have in my installation, other Battery values are reported as a percentage from 0 - 100 (that's what I see for my zwave / iPhone devices). So, from what I see this will make it consistent between components.

Edit: fixed word to be more specific.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I mean other wireless tag devices.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They all report as a decimal, this will fix all WirelessTag devices to be this way.

This is from their example code:

batDisplayPc.text((tag.batteryRemaining * 100).toFixed(0));

http://wirelesstag.net/jshtmlview.aspx?html=index.html&js=styles/client.js

and you can see they all devices report as decimal and they are doing this conversion as well for their UI.

@amelchio amelchio merged commit 667b41d into home-assistant:dev Nov 10, 2018
@ghost ghost removed the in progress label Nov 10, 2018
@balloob balloob mentioned this pull request Nov 29, 2018
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.

4 participants