jason0x43 / hacs-hubitat

A Hubitat integration for Home Assistant
MIT License
203 stars 47 forks source link

Hubitat custom integration not handling Roku variables correctly #288

Open rpiasentin opened 2 months ago

rpiasentin commented 2 months ago

I think I detected a bug in the way Roku commands are being passed through the Habitat integration. Please take a look at the advance. Deb logging. I pulled from Home Assistant. There appears to be a variable tight mismatch related to power and I suspect this is causing my Roku to come on in the middle of the night when they’re being polled :

WSource: custom_components/hubitat/hub.py:484 integration: Hubitat (documentation, issues) First occurred: September 3, 2024 at 8:15:53 PM (14 occurrences) Last logged: 11:53:31 AM

Error handling event : Sensor sensor.roku_spare_12f536_power has device class 'power', state class 'measurement' unit 'W' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'PowerOn' (<class 'str'>) Error handling event : Sensor sensor.roku_spare_12f536_power has device class 'power', state class 'measurement' unit 'W' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'PowerOn' (<class 'str'>) Error handling event <Event device_id="15" device_name="Roku master (F2E2BC)" attribute="supportedInputs" value="["Home","Prime Video","Apple TV","Hulu","Disney Plus","Max","Paramount

Describe the bug

To Reproduce

Screenshots

Environment

jason0x43 commented 2 months ago

Could you get the capabilities for your Roku device?

rpiasentin commented 2 months ago

here is what I can find:

{
 "name": "Roku spare (12F536)",
    "label": "Roku spare (12F536)",
    "type": "Roku TV",
    "id": "31",
    "date": "2024-09-05T08:52:07+0000",
    "model": null,
    "manufacturer": null,
    "room": null,
    "capabilities": [
      "Configuration",
      "Refresh",
      "TV",
      "Polling",
      "AudioVolume",
      "MediaTransport",
      "Initialize",
      "Switch",
      "MediaInputSource"
    ],
    "attributes": {
      "movieMode": null,
      "dataType": "ENUM",
      "values": [
        "unmuted",
        "muted"
      ],
      "switch": "on",
      "transportStatus": "stopped",
      "application": "Roku Dynamic Menu",
      "power": "PowerOn",
      "supportedInputs": "[\"Home\",\"Prime Video\",\"Hulu\",\"Sling TV - Live Sports, News, Shows + Freestream\",\"The Roku Channel\",\"Vudu\",\"ESPN\",\"Roku Media Player\",\"YouTube\",\"Roku Tips & Tricks\",\"Plex - Free Movies & TV\",\"Roku | Getting Started\",\"Disney Plus\",\"Wondrium\",\"Crackle\",\"discovery+ | Stream TV Shows\",\"HBO Max\",\"Apple TV\",\"Freevee\",\"Xumo Play\",\"Netflix\",\"The CW\",\"Paramount Plus\",\"Live TV on The Roku Channel\",\"Kids & Family on The Roku Channel\"]",
      "channel": null,
      "mediaInputSource": "Roku Dynamic Menu",
      "volume": null,
      "picture": null,
      "sound": null,
      "mute": null
    },
    "commands": [
      {
        "command": "channelDown"
      },
      {
        "command": "channelUp"
      },
      {
        "command": "configure"
      },
      {
        "command": "home"
      },
      {
        "command": "initialize"
      },
      {
        "command": "keyPress"
      },
      {
        "command": "mute"
      },
      {
        "command": "off"
      },
      {
        "command": "on"
      },
      {
        "command": "pause"
      },
      {
        "command": "play"
      },
      {
        "command": "poll"
      },
      {
        "command": "queryActiveApp"
      },
      {
        "command": "queryDeviceInfo"
      },
      {
        "command": "queryInstalledApps"
      },
      {
        "command": "queryMediaPlayer"
      },
      {
        "command": "quiter"
      },
      {
        "command": "refresh"
      },
      {
        "command": "reloadApps"
      },
      {
        "command": "search"
      },
      {
        "command": "setChannel"
      },
      {
        "command": "setInputSource"
      },
      {
        "command": "setVolume"
      },
      {
        "command": "stop"
      },
      {
        "command": "unmute"
      },
      {
        "command": "volumeDown"
      },
      {
        "command": "volumeDown10"
      },
      {
        "command": "volumeUp"
      },
      {
        "command": "volumeUp10"
      }
    ]
  }
jason0x43 commented 2 months ago

As far as the error goes, the issue is that the Roku driver and the integration don't agree on what a power attribute should represent. The integration assumes drivers are following Hubitat's device capabilities spec, and in the spec a power attribute is a power measurement. The Roku driver, on the other hand, is using that attribute to report a general power state.

I suspect this is causing my Roku to come on in the middle of the night when they’re being polled.

The integration doesn't poll devices device. However, if you have an automation that's polling the device and trying to make decisions from the power attribute, I can see how you might be running into trouble. Ideally I'd say automations should look at the switch attribute to tell if the device is on or off, but I'm not sure what that driver is using the switch attribute for, so that might not work.

In any case, I'm going to update the integration to consider the device's stated capabilities as well as its attributes when adding power sensors. That should resolve this, although you may need to remove the Roku from the Maker API and re-add it if simply updating the integration doesn't do the trick.