Skip to content

Input needed: Refactor logic setting light state #2475

Closed
@ebaauw

Description

@ebaauw

I've finally found the time to refactor the setting of the state of a /lights resource, see #1111 (comment). Next to the functional changes, I'm also adding parameter checking.

The logic for handling on and bri is described in the issue mentioned above. The logic for handling the other attributes is less clear. I run into some design decisions for these, @manup, everybody, please provide your input.

  1. The Hue API clearly states: xy trumps ct trumps hue and sat. It ignores the over-trumped attributes without issuing an error, but clients can tell because they aren't reported in the response. Not sure how effect is supposed to relate to these. I want to do the following: for "none", clear the colour loop before handling the colour attributes; for "colorloop", set the colour loop after handling the colour attributes. And return an error for the colour attributes while colour loop is active (just as for bri and colour attributes when the light is off).
  2. While not documented, I think the Hue API also acts like: bri trumps bri_inc and ct trumps ct_inc. Note that the deCONZ API doesn't expose xy_inc, hue_inc, nor sat_inc. While they might be great for rule actions for the magic cube, I haven't seen any use for these;
  3. There is no ResourceItem for effect. Looking at the code, effect is exposed only when xy is. On the other hand, setting the colour loop changes colormode to hs?
  4. I'm not sure I fully understand the code handling hue and sat. It would seem the plugin tries to calculate and update the xy values from the hue and sat values for the benefit of taskToLocalData(). Why isn't there similar logic for updating ct. And for updating xy and hue / sat when setting ct? And for updating ct and hue / sat when updating xy?
    I think API clients should take notice of colormode and only process the corresponding attributes (homebridge-hue does).
    I would really like to defer this setting of other colour attributes to the light, although not all non-Hue lights update xy, ct, or hue / sat from other colour modes;
  5. I'm missing an addTaskSetEnhancedHueAndSaturation() in zcl_tasks.cpp. Is that intentional or just for historic reasons? Preferably, I would have a single addTask...() to set any combination of hue/enhanced hue and sat, depending on the light capabilities;
  6. What's the policy for exposing attributes that aren't supported by the light? E.g. exposing ct for Color lights, or hue and sat for lights that don't support these for Alexa's benefit. And for using a different colour mode than specified in the API call to set the colour (e.g. setting hue / sat when xy was specified, or setting xy when ct was specified). How to handle colormode in these cases: I think it should report the actual light mode?
    Personally I feel this is a poor decision, leading only to confusion. If a light doesn't support hue and sat, it doesn't work with Alexa, sorry. If a light doesn't support ct, do the ct to xy conversion in your API client.
  7. Currently a number of non-light devices are exposed as /lights resources: _Window covering device, Warning device, Fan, Range Extender, and Configuration Tool (did I miss any?). For Window covering device, on, bri, and sat are abused for Open, Percentage Lift and Percentage Tilt from the Window covering cluster. For Warning device, alert is abused for Warning from the IAS WD cluster. The only Fan currently (in progress of being) is the Hampton Bay fan module (Fan Module (Hampton Bay) #932), which exposes the Fan Control cluster on the same endpoint as the On/Off and Level Control clusters (to expose the light). The fan is exposed though an added speed attribute. I'm still not sure whether the Fan Control cluster should better be exposed as a separate (for now) /lights resource. The Trådfri repeater supports Identify, and correctly maps that to alert.
    Most of these devices support Groups and Scenes, but the API cannot handle these. In preparation of this, I'd like to change the attributes for Window covering device to open, lift, and tilt (and get rid of the 0..254 to 0..100 translations) and for Warning device to warning. As this would be a breaking change, how do we want to handle that. Expose old and new next to each other for a while?
    It might be prudent to add the cluster to the uniqueid of these non-light /lights resources, but that might also be a breaking change. It would be needed to expose the Hamption Bay as two resources.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BacklogThis label is assigned if it is implemented later.To-Do

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions