Triggers

Triggers are entities comparable with messages received from the Sonos devices.

If the comparison, made through the is_triggered method, returns True than the entity is considered to be triggered.

class soco_plugin.message.Trigger(description: Any, events: List[home.Event] = None)

Build a Trigger from a python dictionary

@param trigger_data: a python dictionary with the trigger data

>>> import io
>>> import json
>>> import home
>>> import soco_plugin
>>> json_trigger = '''
...                {
...                    "name": "play",
...                    "fields": {},
...                    "addresses": ["Bagno"]
...                }
... '''
>>> class Triggerr(soco_plugin.trigger.play.Trigger):
...     pass
>>> fd = io.StringIO(json_trigger)
>>> trigger_data = json.load(fd)
>>> d = Description(trigger_data)
>>> trigger1 = Triggerr(trigger_data, [home.appliance.sound.player.event.forced.Event.On])
>>> trigger1.is_triggered(d)
True
>>> trigger1.events
[<Event.On: 'On'>]
ACTION = None
is_triggered(another_description: soco_plugin.message.Description) bool

This trigger is triggered by the given protocol message Description?

Parameters

another_description – a protocol message description

Returns

bool

classmethod make()

Make a protocol message Description given the arguments.

Parameters
  • args

  • kwargs

Returns

a protocol message Description

classmethod make_from_yaml()

Make a protocol message Description given the yaml arguments.

Parameters
  • args

  • kwargs

Returns

a protocol message Description

Play

class soco_plugin.trigger.play.Trigger(description: Any, events: List[home.Event] = None)
ACTION = 'play'
Msg = {'addresses': [], 'fields': {}, 'name': 'play', 'type': 'soco'}

Pause

class soco_plugin.trigger.pause.Trigger(description: Any, events: List[home.Event] = None)
ACTION = 'pause'
Msg = {'addresses': [], 'fields': {}, 'name': 'pause', 'type': 'soco'}

Stop

class soco_plugin.trigger.stop.Trigger(description: Any, events: List[home.Event] = None)
ACTION = 'stop'
Msg = {'addresses': [], 'fields': {}, 'name': 'stop', 'type': 'soco'}

Volume

class soco_plugin.trigger.volume.Trigger(description: Any, events: List[home.Event] = None)
ACTION = 'volume'
Msg = {'addresses': [], 'fields': {'volume': 1}, 'name': 'volume', 'type': 'soco'}
make_new_state_from(another_description: soco_plugin.message.Description, old_state: home.appliance.attribute.mixin.Volume) bool
>>> import soco_plugin
>>> import home
>>> trigger = soco_plugin.trigger.volume.Trigger.make(["an address",])
>>> old_state = home.appliance.sound.player.state.forced.circadian_rhythm.state.State()
>>> msg = trigger.Msg.copy()
>>> msg["addresses"] = ["an address", ]
>>> d = soco_plugin.Description(msg)
>>> new_state = trigger.make_new_state_from(d, old_state)