show battery_level as a percent vs a decimal#18328
show battery_level as a percent vs a decimal#18328amelchio merged 4 commits intohome-assistant:devfrom chriskacerguis:wireless-tag-battery-fix
Conversation
| """Return the state attributes.""" | ||
| return { | ||
| ATTR_BATTERY_LEVEL: self._tag.battery_remaining, | ||
| ATTR_BATTERY_LEVEL: '{:.0%}'.format(self._tag.battery_remaining), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I mean other wireless tag devices.
There was a problem hiding this comment.
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.
Thanks for your help @amelchio
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_levelattribute is now reported as percent (i.e. 79, not 0.79).Checklist:
tox. Your PR cannot be merged unless tests passIf 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