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

NUT sensor enhancements #14570

Merged
merged 6 commits into from May 22, 2018
Merged

NUT sensor enhancements #14570

merged 6 commits into from May 22, 2018

Conversation

exxamalte
Copy link
Contributor

@exxamalte exxamalte commented May 21, 2018

Description:

This proposal makes the NUT sensor a bit more user-friendly, and contains the following changes:

  • Fix NUT sensor shows raw status instead of human-readable status #14324 by introducing a new virtual sensor type ups.status.display which outputs the UPS status in a human-readable form. For example, outputs "Online Battery Charging" instead of "OL CHRG" on the sensor's state card.
  • Change the more info dialog output by appending the raw status value to the human-readable form. Example output: "state . Online Battery Charging (OL CHRG)".
  • In two cases where during the setup of the sensor the NUT status is unavailable or the initial sensor update fails, raise a PlatformNotReady to make HA try again after a few seconds.

Related issue (if applicable): fixes #14324

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

Example entry for configuration.yaml (if applicable):

sensor:
  - platform: nut
    resources:
      - ups.status.display

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

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

…dy when connection to nut unavailable; output human-readable state name by default
… raw value of current status in more info dialog
…t used to display a human-readable form of the status
@@ -209,11 +215,12 @@ def unit_of_measurement(self):
def device_state_attributes(self):
"""Return the sensor attributes."""
attr = dict()
attr[ATTR_STATE] = self.opp_state()
attr[ATTR_STATE] = self.display_state() + " (" + \
self._data.status[KEY_STATUS] + ")"
Copy link
Member

Choose a reason for hiding this comment

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

Please use format() instead of concats (+)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, makes sense.

@@ -209,11 +215,12 @@ def unit_of_measurement(self):
def device_state_attributes(self):
"""Return the sensor attributes."""
attr = dict()
attr[ATTR_STATE] = self.opp_state()
attr[ATTR_STATE] = "{} ({})".format(self.display_state(),
Copy link
Member

Choose a reason for hiding this comment

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

If you are very accurate this is a breaking change. I would remove the duplicate info here. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are right. And with the introduction of a separate sensor type for the human-readable status, the additional information in the more info dialogue is probably not necessary anymore.

@exxamalte
Copy link
Contributor Author

Is this still a breaking change now that the more info dialogue output remains untouched?

@syssi
Copy link
Member

syssi commented May 22, 2018

Oh! You are right. I've removed the tag again.

@syssi syssi merged commit a2decda into home-assistant:dev May 22, 2018
@fanaticDavid
Copy link
Contributor

Thank you @exxamalte for this fix! 👍

@exxamalte exxamalte deleted the nut-enhancements branch May 22, 2018 23:25
girlpunk pushed a commit to girlpunk/home-assistant that referenced this pull request Sep 4, 2018
…14324)

* removed default value from required parameter; raising PlatformNotReady when connection to nut unavailable; output human-readable state name by default

* removed superfluous sensor name part; showing human-readable form and raw value of current status in more info dialog

* introduced a new virtual sensor type based on the raw status value but used to display a human-readable form of the status

* renamed method

* format string instead of concatenation

* revert the change to the device state attributes - only output the human-readable status without the raw value
@home-assistant home-assistant locked and limited conversation to collaborators Sep 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed integration: nut small-pr PRs with less than 30 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NUT sensor shows raw status instead of human-readable status
4 participants