Commands

Commands are entities capable of forge messages for the Sonos devices interpreting changes in Automate Home Appliances states.

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

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

class soco_plugin.message.Command(data)
execute() List[soco_plugin.message.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[soco_plugin.message.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

Play

class soco_plugin.command.play.Command(data)
>>> import home
>>> import soco_plugin
>>> cmd = soco_plugin.command.play.Command.make(["Bath"])
>>> old_state = home.appliance.sound.player.state.off.State()
>>> new_state = old_state.next(home.appliance.sound.player.event.forced.Event.On)
>>> msg = cmd.make_msgs_from(old_state, new_state)
>>> msg[0]["name"]
'play'
ACTION = 'play'
Msg = {'addresses': [], 'fields': {}, 'name': 'play', 'type': 'soco'}
make_msgs_from(old_state: soco_plugin.command.Mixin, new_state: soco_plugin.command.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

Pause

class soco_plugin.command.pause.Command(data)
>>> import home
>>> import soco_plugin
>>> cmd = soco_plugin.command.pause.Command.make(["Bath"])
>>> old_state = home.appliance.sound.player.state.off.State()
>>> old_state = old_state.next(home.appliance.sound.player.event.forced.Event.On)
>>> new_state = old_state.next(home.appliance.sound.player.event.forced.Event.Off)
>>> msg = cmd.make_msgs_from(old_state, new_state)
>>> msg[0]["name"]
'pause'
ACTION = 'pause'
Msg = {'addresses': [], 'fields': {}, 'name': 'pause', 'type': 'soco'}
make_msgs_from(old_state: soco_plugin.command.Mixin, new_state: soco_plugin.command.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

Stop

class soco_plugin.command.stop.Command(data)
>>> import home
>>> import soco_plugin
>>> cmd = soco_plugin.command.stop.Command.make(["Bath"])
>>> old_state = home.appliance.sound.player.state.off.State()
>>> old_state = old_state.next(home.appliance.sound.player.event.forced.Event.On)
>>> new_state = old_state.next(home.appliance.sound.player.event.forced.Event.Off)
>>> msg = cmd.make_msgs_from(old_state, new_state)
>>> msg[0]["name"]
'stop'
ACTION = 'stop'
Msg = {'addresses': [], 'fields': {}, 'name': 'stop', 'type': 'soco'}
make_msgs_from(old_state: soco_plugin.command.Mixin, new_state: soco_plugin.command.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

Playlist

class soco_plugin.command.playlist.Command(data)
>>> import home
>>> import soco_plugin
>>> cmd = soco_plugin.command.playlist.Command.make(["Bath"])
>>> old_state = home.appliance.sound.player.state.off.State()
>>> old_state = old_state.next(home.appliance.sound.player.event.forced.Event.On)
>>> new_state = old_state.next(home.appliance.sound.player.event.playlist.Event("A new playlist"))
>>> msg = cmd.make_msgs_from(old_state, new_state)
>>> msg[0]["fields"]["title"]
'A new playlist'
ACTION = 'playlist'
Msg = {'addresses': [], 'fields': {'title': 'Unknown'}, 'name': 'playlist', 'type': 'soco'}
make_msgs_from(old_state: soco_plugin.command.Mixin, new_state: soco_plugin.command.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

Mode

class soco_plugin.command.mode.Command(data)
>>> import home
>>> import soco_plugin
>>> cmd = soco_plugin.command.playlist.Command.make(["Bath"])
>>> old_state = home.appliance.sound.player.state.off.State()
>>> old_state = old_state.next(home.appliance.sound.player.event.forced.Event.On)
>>> new_state = old_state.next(home.appliance.sound.player.event.playlist.Event("A new playlist"))
>>> msg = cmd.make_msgs_from(old_state, new_state)
>>> msg[0]["fields"]["title"]
'A new playlist'
class Mode(value)

An enumeration.

NORMAL = 'NORMAL'
REPEAT_ALL = 'REPEAT_ALL'
SHUFFLE = 'SHUFFLE'
SHUFFLE_NOREPEAT = 'SHUFFLE_NOREPEAT'
REPEAT_ONE = 'REPEAT_ONE'
SHUFFLE_REPEAT_ONE = 'SHUFFLE_REPEAT_ONE'
ACTION = 'play_mode'
Msg = {'addresses': [], 'fields': {'mode': 'SHUFFLE'}, 'name': 'play_mode', 'type': 'soco'}
make_msgs_from(old_state: home.appliance.state.State, new_state: home.appliance.state.State)

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

Volume Absolute

class soco_plugin.command.volume.absolute.Command(data)
>>> import home
>>> import soco_plugin
>>> cmd = soco_plugin.command.volume.absolute.Command.make(["Bath"])
>>> old_state = home.appliance.sound.player.state.off.State()
>>> new_state = old_state.next(home.appliance.sound.player.event.forced.Event.On)
>>> new_state = new_state.next(home.appliance.sound.player.event.volume.Event(66))
>>> new_state = new_state.next(home.appliance.sound.player.event.sleepy_volume.Event(33))
>>> new_state = new_state.next(home.event.sleepiness.Event.Awake)
>>> msg = cmd.make_msgs_from(old_state, new_state)
>>> msg[0]["fields"]["value"]
66
>>> new_state = new_state.next(home.event.sleepiness.Event.Sleepy)
>>> msg = cmd.make_msgs_from(old_state, new_state)
>>> msg[0]["fields"]["value"]
33
ACTION = 'absolute_volume'
Msg = {'addresses': [], 'fields': {'value': 10}, 'name': 'absolute_volume', 'type': 'soco'}
make_msgs_from(old_state: soco_plugin.command.Mixin, new_state: soco_plugin.command.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

Volume Relative

class soco_plugin.command.volume.relative.Command(data)
>>> import home
>>> import soco_plugin
>>> cmd = soco_plugin.command.volume.relative.Command.make(["Bath"])
>>> old_state = home.appliance.sound.player.state.off.State()
>>> new_state = old_state.next(home.appliance.sound.player.event.forced.Event.On)
>>> new_state = new_state.next(home.appliance.sound.player.event.volume.Event(66))
>>> new_state = new_state.next(home.appliance.sound.player.event.sleepy_volume.Event(33))
>>> new_state = new_state.next(home.event.sleepiness.Event.Awake)
>>> msg = cmd.make_msgs_from(old_state, new_state)
>>> msg[0]["fields"]["delta"]
10
>>> new_state = new_state.next(home.event.sleepiness.Event.Sleepy)
>>> msg = cmd.make_msgs_from(old_state, new_state)
>>> msg[0]["fields"]["delta"]
10
ACTION = 'relative_volume'
Msg = {'addresses': [], 'fields': {'delta': 10}, 'name': 'relative_volume', 'type': 'soco'}
make_msgs_from(old_state: soco_plugin.command.Mixin, new_state: soco_plugin.command.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

Volume Ramp

class soco_plugin.command.volume.ramp.Command(data)
>>> import home
>>> import soco_plugin
>>> cmd = soco_plugin.command.volume.ramp.Command.make(["Bath"])
>>> old_state = home.appliance.sound.player.state.off.State()
>>> old_state = old_state.next(home.event.presence.Event.On)
>>> old_state = old_state.next(home.event.sleepiness.Event.Asleep)
>>> new_state = old_state.next(home.event.sleepiness.Event.Awake)
>>> msg = cmd.make_msgs_from(old_state, new_state)
>>> msg[0]["fields"]["volume"]
30
>>> msg[0]["fields"]["ramp_type"]
'SLEEP_TIMER_RAMP_TYPE'
class RampType(value)

An enumeration.

SLEEP_TIMER_RAMP_TYPE = 'SLEEP_TIMER_RAMP_TYPE'
ALARM_RAMP_TYPE = 'ALARM_RAMP_TYPE'
AUTOPLAY_RAMP_TYPE = 'AUTOPLAY_RAMP_TYPE'
ACTION = 'ramp_to_volume'
Msg = {'addresses': [], 'fields': {'ramp_type': 'SLEEP_TIMER_RAMP_TYPE', 'volume': 10}, 'name': 'ramp_to_volume', 'type': 'soco'}
make_msgs_from(old_state: soco_plugin.command.Mixin, new_state: soco_plugin.command.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