Webthing-python documentation of events as examples

Let’s start a list of code examples.
If you have an example and give me a link or a snippet I will add it to documentation.
Let me know…

@mrstegeman once shared me this example of an event:
from this resource:


        # Add a 'playlistUpdated' event.
            {'description': 'The current playlist has been updated',
             'type': 'string'})


class PlaylistUpdatedEvent(Event):
    """Event to indicate that the current playlist was updated."""

    def __init__(self, thing, data):
        """Initialize the event."""
        Event.__init__(self, thing, 'playlistUpdated', data=data)

It gets triggerd once a Playlist is activated (L548) and eatch time that Playlist adds a random track. on Line 94 from an Action:

# Since we just updated the playlist, emit an event.
playlist = self.thing.get_playlist()
if playlist is not None:
    PlaylistUpdatedEvent(self.thing, playlist))

L548 from inside it self.:

# The current playlist was updated, so emit an event.
playlist = self.get_playlist()
if playlist is not None:
    PlaylistUpdatedEvent(self, playlist))