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
Pause
Stop
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)