Pyhass / Hive-Custom-Component

A custom version of the home assistant hive component
MIT License
33 stars 17 forks source link

[BUG] Power usage no longer appearing for Active Plugs since upgrade to 2021.5.1 #96

Closed mansbo closed 3 years ago

mansbo commented 3 years ago

Describe the bug Since upgrading to the latest version 2021.5.1, I am no longer seeing power usage reported by my two Hive Active Plugs. It used to appear as an attribute called current_power_w, but that attribute no longer appears for the plugs. I downgraded back to an earlier version (2021.4.0) and the power usage re-appeared.

To Reproduce

  1. Upgrade to 2021.5.1.
  2. Check attributes of switch entity for the plug - there is no current_power_w listed.

Expected behaviour I would expect the power usage to be reported as an attribute called current_power_w against the switch entity for the plug, as it was in earlier versions.

lwsrbrts commented 3 years ago

This is a kind of me too but with a little more info.

I initially manually installed as a custom component and that has been working perfectly. I decided with the 2FA bits now being part of the main Home Assistant repo that I'd update to use that so I:

Afterwards I updated a few lovelace bits and all seemed ok however, like the OP, the current_power_w attribute is not available for my Active Plugs which I discovered because I have a sensor template, so it was flagged in the logs.

I attempted to undo by removing the built-in integration and re-installing the custom component from here but the code in this repo now seems to import the code from the built-in integration in Home Assistant as of 2021.4 so I got the same result.

To get myself working again, I had to go back to the old code, which I think might have been beta01 - I didn't try any other release.

Directly comparing the current code in core/homeassistant/components/hive/switch.py with the code in this repo before it starts importing from core (2021.3.1) shows only minor changes:

Core (current)

https://github.com/home-assistant/core/blob/ccf92e4721bf7c39c11c0239b81252342a244a35/homeassistant/components/hive/switch.py#L63-L66

    @property
    def current_power_w(self):
        """Return the current power usage in W."""
        return self.device["status"].get("power_usage")

2021.3.1 (from this repo)

https://github.com/home-assistant/core/blob/4d0955bae142421887df47483aff18d1b9e4ef5e/homeassistant/components/hive/switch.py#L63-L66

    @property
    def current_power_w(self):
        """Return the current power usage in W."""
        return self.device["status"]["power_usage"]

May be useful information, may be complete cobblers.

mansbo commented 3 years ago

Well spotted @lwsrbrts - I was staring at the code trying to spot differences but completely missed this one. I think it does point to the problem. The new version of the underlying apyhiveapi library seems to format the device details differently, hence the change, but what is actually happening is that "power_usage" is at a lower level than "status" for Active Plugs, so the new code comes back with None. In fact, there is another "status" object embedded within the "status" being searched for "power_usage". So either this switch.py code needs to look down another level, or the underlying library needs to be changed to lift "power_usage" up to where it needs to be. I suspect the latter but, to be honest, I don't really know what I'm talking about so this could all be complete cobblers too.

perjury commented 3 years ago

me too - sorry, haven't had chance to do any investigation ;-)

KJonline commented 3 years ago

Fixed in 2021.5.3