cgarwood / homeassistant-fullykiosk

Fully Kiosk Browser integration for Home Assistant
Apache License 2.0
153 stars 27 forks source link

Fix KeyError in switch.py and light.py #19

Closed geeto1969 closed 4 years ago

geeto1969 commented 4 years ago

Screensaver key should be 'isInScreensaver' Screen on key should be 'screenOn'

The following errors are observed with Fully Kiosk App v1.40.3 and v1.42.2, possibly due to an API update in the app:

2020-10-11 15:24:59 ERROR (MainThread) [homeassistant.components.switch] Error while setting up fullykiosk platform for switch
Traceback (most recent call last):
  ...
  File "/workspaces/core/homeassistant/helpers/entity.py", line 676, in state
    return STATE_ON if self.is_on else STATE_OFF
  File "/workspaces/core/config/custom_components/fullykiosk/switch.py", line 73, in is_on
    return self.coordinator.data["currentFragment"] == "screensaver"
KeyError: 'currentFragment'

020-10-11 15:24:59 ERROR (MainThread) [homeassistant.components.light] Error while setting up fullykiosk platform for light
Traceback (most recent call last):
  ...
  File "/workspaces/core/homeassistant/helpers/entity.py", line 676, in state
    return STATE_ON if self.is_on else STATE_OFF
  File "/workspaces/core/config/custom_components/fullykiosk/light.py", line 38, in is_on
    return self.coordinator.data["isScreenOn"]
KeyError: 'isScreenOn'
cgarwood commented 4 years ago

I reached out to the Fully Kiosk developer and found that the API changed in version code 784, so we should add a version check self.coordinator.data["appVersionCode"] < 784 use the old keys, otherwise use the new keys

geeto1969 commented 4 years ago

I reached out to the Fully Kiosk developer and found that the API changed in version code 784, so we should add a version check self.coordinator.data["appVersionCode"] < 784 use the old keys, otherwise use the new keys

Thanks for this information. I'll update my contribution to include this check. Unfortunately, I don't have an older version of Fully Kiosk to use for validation. After this fix, I may look at dealing with API updates generally.

geeto1969 commented 4 years ago

Added check for appVersionCode.

Noticed a number of other issues related to similar resources accessed through cmd=deviceInfo, the command used by python-fullykiosk, and cmd=getDeviceInfo, the command currently specified in the Fully Kiosk API documentation. Using cmd=getDeviceInfo will return versionCode instead of appVersionCode. This will break the fix if python-fullykiosk is updated in the future to use the most current API.

cgarwood commented 4 years ago

Yeah, the cmd=getDeviceInfo was added around the same time, supposed to unify the api data between REST and MQTT. We'll want to switch to using that eventually

cgarwood commented 4 years ago

PR looks good, thanks!