Skip to content

Instantly share code, notes, and snippets.

@OttoWinter
Last active February 21, 2018 13:24
Show Gist options
  • Save OttoWinter/58ce0fd4c7743d233af8a10ed7ff940a to your computer and use it in GitHub Desktop.
Save OttoWinter/58ce0fd4c7743d233af8a10ed7ff940a to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@NovapaX
Copy link

NovapaX commented Feb 21, 2018

Why not map all on_states into a 'combined' state first?
(just make each attribute into a list of values, order is not important right?)

So you would work with:

on_states: {
   'brightness': [255, 232, 200]
    'xy_color': [[1.0, 1.0],[1.2, 1.2],[1.5, 1.1],
    'rgb_color': [[255, 255, 255],[255, 255, 255],[255, 255, 255]]
    'white_value': [0, 0, 0.1]
    'supported_features': [1, 2, 345]
})

Then you only need to iterate the states once and can just pass each attributes list to your reduce function.

Oh, and that first (and faster) function a A LOT more readable. (that counts too imo)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment