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

show battery_level as a percent vs a decimal #18328

Merged
merged 4 commits into from Nov 10, 2018

Conversation

Projects
None yet
4 participants
@chriskacerguis
Contributor

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

@@ -271,7 +271,7 @@ def update(self):
def device_state_attributes(self):
"""Return the state attributes."""
return {
ATTR_BATTERY_LEVEL: self._tag.battery_remaining,
ATTR_BATTERY_LEVEL: '{:.0%}'.format(self._tag.battery_remaining),

This comment has been minimized.

@mvn23

mvn23 Nov 9, 2018

Contributor

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?

This comment has been minimized.

@chriskacerguis

chriskacerguis Nov 9, 2018

Contributor

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.

This comment has been minimized.

@mvn23

mvn23 Nov 9, 2018

Contributor

I mean other wireless tag devices.

This comment has been minimized.

@chriskacerguis

chriskacerguis Nov 9, 2018

Contributor

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.

chriskacerguis added some commits Nov 10, 2018

@amelchio amelchio merged commit 667b41d into home-assistant:dev Nov 10, 2018

5 checks passed

Hound No violations found. Woof!
WIP ready for review
Details
cla-bot Everyone involved has signed the CLA
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.0009%) to 93.046%
Details

@wafflebot wafflebot bot removed the in progress label Nov 10, 2018

sqldiablo added a commit to sqldiablo/home-assistant that referenced this pull request Nov 12, 2018

sqldiablo added a commit to sqldiablo/home-assistant that referenced this pull request Nov 12, 2018

zxdavb added a commit to zxdavb/home-assistant that referenced this pull request Nov 13, 2018

@balloob balloob referenced this pull request Nov 29, 2018

Merged

0.83 #18776

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment