openhab-addons: [yeelight] UI not updating when device controlled by services other than openHAB

Expected Behavior

When light is controlled by a non-openHAB service (for example Google Home), the state of the item should update in openHAB UIs (like Basic UI).

Current Behavior

When light is controlled by a non-OpenHAB service (for example Google Home), the state of the item updates but not the UI on OpenHAB. An example is - turning off the light in Google Home does not change the displayed status on Basic UI from On to Off. Openhab logs show that it detects when the state has been changed (isPowerOff): 2019-01-30 20:47:00.208 [INFO ] [light.internal.lib.device.DeviceBase] - status = DeviceStatus [isPowerOff=false, r=255, g=127, b=0, color=16744192, brightness=50, ct=4000, hue=359, sat=100, isFlowing=false, delayOff=-1, mFlowItems=null, mode=MODE_COLOR, isMusicOn=false, name=]

Possible Solution

In YeelightHandlerBase.java it seems the intention is that if ‘isPowerOff’ state is set then the UI should change. void updateBrightnessAndColorUI(DeviceStatus status) { if (status.isPowerOff()) { updateState(YeelightBindingConstants.CHANNEL_BRIGHTNESS, new PercentType(0));

When a change of status occurs the binding appears to detect it and update the state of the device: And when I look in DeviceBase.java and at onNotify there is code where the status is updated: if (prop.getKey().equals("power")) { updateProp += " power"; if (prop.getValue().toString().equals("\"off\"")) { mDeviceStatus.setPowerOff(true); } else if (prop.getValue().toString().equals("\"on\"")) { mDeviceStatus.setPowerOff(false); }

I’ve noticed a ‘listener’ class (DeviceStatusChangeListener.java) which I assume is meant to tell classes that contain devices, like YeelightHandlerBase, that a device instance state has changed. public void onStatusChanged(String prop, DeviceStatus status) { logger.debug("UpdateState->{}", status); updateUI(status); }

However it obviously isn’t being called despite it being mentioned in DeviceBase: if (needNotify) { logger.info("status = {}", mDeviceStatus.toString()); for (DeviceStatusChangeListener statusChangeListener : mStatusChangeListeners) { statusChangeListener.onStatusChanged(updateProp.trim(), mDeviceStatus); } }

Steps to Reproduce (for Bugs)

  1. Request Google Home to turn off or on the light.

Context

The outcome is that you no longer have an accurate display of the state of the light on the OpenHAB UIs

Your Environment

  • Version used: openHAB 2.5.0.M1 Milestone Build
  • Operating System and version: Openhabianpi
  • Yeelight Colour LED V1 (Wonder)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 47

Commits related to this issue

Most upvoted comments

Works perfectly! Brilliant. Thanks for fixing it!