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:
https://github.com/mrstegeman/mpd-webthing/blob/master/python/mpd-webthing.py

L293:

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

L97:

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:
    self.thing.add_event(
    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:
    self.add_event(
    PlaylistUpdatedEvent(self, playlist))