kw123 / Hue-Lights-Indigo-plugin

Philips Hue control from Indigo
MIT License
7 stars 11 forks source link

v2022.11.26 - broken set color temperature actions #15

Closed virtzilla closed 1 year ago

virtzilla commented 2 years ago

Also posted this in the Indigo support forum

I upgraded to v2022.11.26 plugin after struggling with 2022.11.24 and non-dimmable devices resulting in some puzzlement as to why many of our timed outdoor lights had us in the dark.

Many of the timed actions in our setup rely on the plugin's set color temp action. That action seems to have somehow broken in v2022.11.26.

I get this error in the logs when the set color temp action fires:

   Hue Lights Error                
Traceback (most recent call last):
  File "plugin.py", line 9570, in setColorTemperature
    if groupId is None or groupId == 0:
UnboundLocalError: local variable 'groupId' referenced before assignment
virtzilla commented 2 years ago

I tried re-adding the removed lines that set groupID and bulbId, i.e. (starting at line 9568):

            if device.deviceTypeId == "hueGroup":
                # Sanity check on group ID
                # re-added following line from prior working version
                groupId = device.pluginProps.get('groupId', None)

                if groupId is None or groupId == 0:
                    self.doErrorLog(u"No group ID selected for device \"{}\". Check settings for this device and select a Hue Group to control.".format(device.name))
                    return
            else:
                # Sanity check on bulb ID
                # re-added following line from prior working version
                bulbId = device.pluginProps.get('bulbId', None)
                if bulbId is None or bulbId == 0:
                    self.doErrorLog(u"No bulb ID selected for device \"{}\". Check settings for this device and select a Hue Device to control.".format(device.name))
                    return

The prior error went away, but another cropped up:

   Schedule                        On - Front Yard Hue Lights
   Hue Lights                      Sent Hue Lights  "Front Yard - Lights" on to 1 using color temperature  2900K.  at ramp rate  1.0 sec.
   Hue Lights Error                Error in plugin execution runConcurrentThread:

  File "plugin.py", line 518, in runConcurrentThread
  File "plugin.py", line 5383, in excecStatesUpdate
type: dictionary changed size during iteration

   Hue Lights Error                plugin runConcurrentThread function returned or failed (will attempt again in 10 seconds)

Pondering if using the actions on a group (which is awesome when it works) might be less common.

kw123 commented 2 years ago

Sorry I can’t really do anything right now. Don’t have access to the files.

Karl

On 08.06.2022, at 08:19, virtzilla @.***> wrote:

 I tried re-adding the removed lines that set groupID and bulbId, i.e. (starting at line 9568):

` if device.deviceTypeId == "hueGroup":

Sanity check on group ID

re-added following line from prior working version

groupId = device.pluginProps.get('groupId', None)

      if groupId is None or groupId == 0:
          self.doErrorLog(u"No group ID selected for device \"{}\". Check settings for this device and select a Hue Group to control.".format(device.name))
          return
  else:
      # Sanity check on bulb ID
      # re-added following line from prior working version
      **bulbId = device.pluginProps.get('bulbId', None)**
      if bulbId is None or bulbId == 0:
          self.doErrorLog(u"No bulb ID selected for device \"{}\". Check settings for this device and select a Hue Device to control.".format(device.name))
          return

` The prior error went away, but another cropped up:

` Schedule On - Front Yard Hue Bollards Hue Lights Sent Hue Lights "Front Yard - Bollards" on to 1 using color temperature 2900K. at ramp rate 1.0 sec. Hue Lights Error Error in plugin execution runConcurrentThread:

File "plugin.py", line 518, in runConcurrentThread File "plugin.py", line 5383, in excecStatesUpdate type: dictionary changed size during iteration

Hue Lights Error plugin runConcurrentThread function returned or failed (will attempt again in 10 seconds) `

Pondering if using the actions on a group (which is awesome when it works) might be less common.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.

virtzilla commented 2 years ago

changing line 5383 in plugin.py from: for devId in self.updateList:

to this, casting the items to a list: for devId in list(self.updateListi):

avoids the issue with the list changing while it's being iterated over. This seems to resolve the issue at hand for the color temp actions (with the changes noted above to fix variable assignment).

From looking through the changes that cause the first set of challenges above, it does seem that perhaps the cleanup on the code was perhaps a tad too aggressive. It also has me thinking that perhaps some unit tests would be valuable, to insure the robustness of the plugin and insure sections of the code are behaving as intended. I worry there might be other sections of code that were removed that are now waiting for me to hit them when they get exercised.

Something to ponder when you get back from what i hope was an awesome adventure.

kw123 commented 2 years ago

this is a timing issue. Actions run separately from the regular processes. It also wants to add to the self.updateList.

While other processes are running the self.updateList gets changed. Making a list out of it does not solve the problem: it copies the index. We need to copy the whole dictionary.

like this:

def excecStatesUpdate(self):
    temp = copy.deepcopy(self.updateList)
    self.updateList = {}
    for devId in temp:
        indigo.devices[devId].updateStatesOnServer(temp[devId])

Karl

On Jun 17, 2022, at 06:10, virtzilla @.***> wrote:

changing line 5383 in plugin.py from:

for devId in self.updateList: to this, casting the items to a list:

for devId in list(self.updateListi): avoids the issue with the list changing while it's being iterated over. This seems to resolve the issue at hand for the color temp actions.

From looking through the changes that cause the first set of challenges above, it does seem that perhaps the cleanup on the code was perhaps a tad too aggressive. It also has me thinking that perhaps some unit tests would be valuable, to insure the robustness of the plugin and insure sections of the code are behaving as intended. I worry there might be other sections of code that were removed that are now waiting for me to hit them when they get exercised.

Something to ponder when you get back from what i hope was an awesome adventure.

— Reply to this email directly, view it on GitHub https://github.com/kw123/Hue-Lights-Indigo-plugin/issues/15#issuecomment-1158469880, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEH2SNGB3LHQXE2MZMXQOIDVPP3BZANCNFSM5YALHLAA. You are receiving this because you commented.

virtzilla commented 2 years ago

Just to follow up on this, 2022.11.27 and later appear to have resolved the issue I was experiencing initially and subsequently (with my workaround hacks). If a user perspective is holding this issue open, I think you can close it.

Additionally as a point of reference: 2022.11.28 was stable in my environment for more than a week with no observed issues, and 2022.11.29 has been trouble free for 3+ days.

kw123 commented 1 year ago

.31 has fixed a bug for dimmer only devices. Onstate was not updated properly

Karl

On 01.07.2022, at 20:26, virtzilla @.***> wrote:

 Just to follow up on this, 2022.11.27 and later appear to have resolved the issue I was experiencing initially and subsequently (with my workaround hacks). If a user perspective is holding this issue open, I think you can close it.

Additionally as a point of reference: 2022.11.28 was stable in my environment for more than a week with no observed issues, and 2022.11.29 has been trouble free for 3+ days.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.