Commands

Commands are entities capable of forge messages for the Lifx bus interpreting changes in Appliance state.

Commands compare an old Appliance state with a new one and create messages to be sent to the Appliance’s device.

Commands are designed to read Appliance’s attributes: home.appliance.attribute.mixin()

class lifx_plugin.message.Command(data: dict)
>>> import io
>>> import json
>>> import lifx
>>> import home
>>> command_data = '''
...                {
...                    "name": "SetColor",
...                    "fields": {"hue": 20, "saturation": 20, "brightness": 20, "kelvin": 3500, "duration": 1024},
...                    "addresses": [["172.31.10.245", 56700]]
...                }
... '''
>>> fd = io.StringIO(command_data)
>>> command_data = json.load(fd)
>>> command = Command(command_data)
>>> command.execute()
[[0x31, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x00, 0x39, 0x0E, 0x33, 0x33, 0x33, 0x33, 0xAC, 0x0D, 0x00, 0x04, 0x00, 0x00]]
>>> print(command)
Command SetColor {hue: 20, saturation: 20, brightness: 20, kelvin: 3500, rgb: (51, 44, 41), duration: 1024} to [172.31.10.245:56700]
execute() List[lifx.lan.msg.Msg]

Build one or more messages for the protocol Gateway, using the internal protocol message representation

Returns

a list of protocol messages

make_msgs_from(old_state: home.appliance.state.State, new_state: home.appliance.state.State) List[lifx.lan.msg.Msg]

Update the internal protocol message representation and call execute to build one or more messages for the protocol Gateway

Parameters
  • old_state – the old Appliance State

  • new_state – the new Appliance State

Returns

a list of protocol messages

Set Color

class lifx_plugin.command.SetColor(data: dict)

Set the right color when turned on. When off it is not able to listen new commands.

Use when the command is called time after the state is changed and the old_state is not different from new_state. Lifx Bulb takes almost 7 seconds to start and be able to listen new commands.

>>> import home
>>> import lifx
>>> import lifx_plugin
>>> old_state = home.appliance.light.indoor.hue.state.off.State()
>>> new_state = old_state.next(home.appliance.light.event.hue.Event(30))
>>> new_state = new_state.next(home.appliance.light.event.saturation.Event(30))
>>> new_state = new_state.next(home.appliance.light.event.brightness.Event(30))
>>> new_state = new_state.next(home.appliance.light.event.temperature.Event(30))
>>> new_state = new_state.next(home.appliance.light.event.circadian_rhythm.hue.Event(40))
>>> new_state = new_state.next(home.appliance.light.event.circadian_rhythm.saturation.Event(40))
>>> new_state = new_state.next(home.appliance.light.event.circadian_rhythm.brightness.Event(40))
>>> new_state = new_state.next(home.appliance.light.event.circadian_rhythm.temperature.Event(40))
>>> new_state = new_state.next(home.appliance.light.event.lux_balancing.brightness.Event(50))
>>> new_state = new_state.next(home.appliance.light.event.show.starting_brightness.Event(60))
>>> new_state = new_state.next(home.appliance.light.event.show.starting_hue.Event(60))
>>> new_state = new_state.next(home.appliance.light.indoor.dimmerable.event.forced.Event.On)
>>> command = SetColor.make([["172.31.10.245", 56700], ])
>>> msgs = command.make_msgs_from(old_state, new_state)
>>> "brightness: 30" in str(lifx_plugin.Description.make_from(msgs[0]))
True
>>> new_state = new_state.next(home.appliance.light.indoor.dimmerable.event.forced.Event.Not)
>>> new_new_state = new_state.next(home.appliance.light.indoor.dimmerable.event.forced.Event.CircadianRhythm)
>>> msgs = command.make_msgs_from(new_state, new_new_state)
>>> "brightness: 40" in str(lifx_plugin.Description.make_from(msgs[0]))
True
>>> new_new_state = new_state.next(home.appliance.light.indoor.dimmerable.event.forced.Event.LuxBalance)
>>> msgs = command.make_msgs_from(new_state, new_new_state)
>>> "brightness: 50" in str(lifx_plugin.Description.make_from(msgs[0]))
True
>>> new_new_state = new_state.next(home.appliance.light.indoor.dimmerable.event.forced.Event.Show)
>>> msgs = command.make_msgs_from(new_state, new_new_state)
>>> "brightness: 60" in str(lifx_plugin.Description.make_from(msgs[0]))
True
State = {'addresses': [], 'fields': {'brightness': 100, 'duration': 1024, 'hue': 0, 'kelvin': 3500, 'saturation': 0}, 'name': 'SetColor', 'type': 'lifx'}
make_msgs_from(old_state: lifx_plugin.Mixin, new_state: lifx_plugin.Mixin)

Update the internal protocol message representation and call execute to build one or more messages for the protocol Gateway

Parameters
  • old_state – the old Appliance State

  • new_state – the new Appliance State

Returns

a list of protocol messages

Set Waveform

class lifx_plugin.command.SetWaveform(data: dict)

Always set waveform when showing.

Use when the command is called time after the state is changed and the old_state is not different from new_state. Lifx Bulb takes almost 7 seconds to start and be able to listen new commands.

>>> import home
>>> import lifx
>>> import lifx_plugin
>>> old_state = home.appliance.light.indoor.hue.state.off.State()
>>> new_state = old_state.next(home.appliance.light.event.hue.Event(30))
>>> new_state = new_state.next(home.appliance.light.event.saturation.Event(30))
>>> new_state = new_state.next(home.appliance.light.event.brightness.Event(30))
>>> new_state = new_state.next(home.appliance.light.event.temperature.Event(30))
>>> new_state = new_state.next(home.appliance.light.event.show.starting_brightness.Event(60))
>>> new_state = new_state.next(home.appliance.light.event.show.ending_brightness.Event(80))
>>> new_state = new_state.next(home.appliance.light.event.show.starting_hue.Event(60))
>>> new_state = new_state.next(home.appliance.light.event.show.ending_hue.Event(80))
>>> new_state = new_state.next(home.appliance.light.event.show.cycles.Event(60))
>>> new_state = new_state.next(home.appliance.light.event.show.period.Event(60))
>>> new_state = new_state.next(home.appliance.light.indoor.dimmerable.event.forced.Event.Show)
>>> command = SetWaveform.make([["172.31.10.245", 56700], ])
>>> msgs = command.make_msgs_from(old_state, new_state)
>>> "brightness: 80" in str(lifx_plugin.Description.make_from(msgs[0]))
True
State = {'addresses': [], 'fields': {'brightness': 90, 'cycles': 30, 'duration': 1000, 'hue': 335, 'kelvin': 3500, 'period': 180000, 'saturation': 90, 'skew_ratio': 0.5, 'transient': True, 'waveform': 'sine'}, 'name': 'SetWaveform', 'type': 'lifx'}
make_msgs_from(old_state: lifx_plugin.Mixin, new_state: lifx_plugin.Mixin)

Update the internal protocol message representation and call execute to build one or more messages for the protocol Gateway

Parameters
  • old_state – the old Appliance State

  • new_state – the new Appliance State

Returns

a list of protocol messages