Skip to content

Remove % sign from Vera Battery Levels#8069

Merged
fabaff merged 1 commit into
home-assistant:devfrom
philhawthorne:vera-battery-percents
Jun 17, 2017
Merged

Remove % sign from Vera Battery Levels#8069
fabaff merged 1 commit into
home-assistant:devfrom
philhawthorne:vera-battery-percents

Conversation

@philhawthorne
Copy link
Copy Markdown
Contributor

Description:

Vera devices are reporting battery levels as a sting by appending a
percentage sign (%) on the end.

To make the Vera component act like other Home Assistant components,
let's remove the percentage sign from the battery report levels so that
we only display the battery level.

This may be a "breaking change" if people are relying on the Vera
battery levels to be a string instead of an int. However, this will make
the battery level reports compatible with everything else.

Related issue (if applicable): See discussion in #7879

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

Checklist:

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

Vera devices are reporting battery levels as a sting by appending a
percentage sign (%) on the end.

To make the Vera component act like other Home Assistant components,
let's remove the percentage sign from the battery report levels so that
we only display the battery level.

This may be a "breaking change" if people are relying on the Vera
battery levels to be a string instead of an int. However, this will make
the battery level reports compatible with everything else.
@mention-bot
Copy link
Copy Markdown

@philhawthorne, thanks for your PR! By analyzing the history of the files in this pull request, we identified @pavoni, @arjenfvellinga and @balloob to be potential reviewers.

Copy link
Copy Markdown
Member

@fabaff fabaff left a comment

Choose a reason for hiding this comment

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

Thanks 🐦

@fabaff fabaff merged commit 9071946 into home-assistant:dev Jun 17, 2017
@balloob balloob mentioned this pull request Jul 1, 2017

if self.vera_device.has_battery:
attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%'
attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think that this has the desired effect. Python does not allow concatenation of a number and a string, so the battery level itself must be a number in string form. So the attribute is still a string?

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.

@balloob you might be right on that.

The original intention was for InfluxDB, which would handle the string to number conversion.

Should we wrap self.vera_device.battery_level around a float()?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yes (or int if it's just a number?). And catch the TypeError in case the conversion fails. When failed, just not add that attribute (that way the data in that field stays of a consistent type)

@home-assistant home-assistant locked and limited conversation to collaborators Oct 20, 2017
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.

5 participants