From cc36325ca6a9853fb9c5998a7086899b56872f3b Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 28 Oct 2020 23:28:41 +0100 Subject: [PATCH] Added support for custom user events --- docs/source/events.rst | 1 + docs/source/platypush/events/custom.rst | 5 +++++ platypush/message/event/custom.py | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 docs/source/platypush/events/custom.rst create mode 100644 platypush/message/event/custom.py diff --git a/docs/source/events.rst b/docs/source/events.rst index e1774df69..4e1ce08a6 100644 --- a/docs/source/events.rst +++ b/docs/source/events.rst @@ -16,6 +16,7 @@ Events platypush/events/chat.telegram.rst platypush/events/clipboard.rst platypush/events/covid19.rst + platypush/events/custom.rst platypush/events/distance.rst platypush/events/foursquare.rst platypush/events/geo.rst diff --git a/docs/source/platypush/events/custom.rst b/docs/source/platypush/events/custom.rst new file mode 100644 index 000000000..4c51b5bb2 --- /dev/null +++ b/docs/source/platypush/events/custom.rst @@ -0,0 +1,5 @@ +``platypush.message.event.custom`` +================================== + +.. automodule:: platypush.message.event.custom + :members: diff --git a/platypush/message/event/custom.py b/platypush/message/event/custom.py new file mode 100644 index 000000000..4b79fd7b5 --- /dev/null +++ b/platypush/message/event/custom.py @@ -0,0 +1,18 @@ +from platypush import Event + + +class CustomEvent(Event): + """ + This type can be used to fire custom events upon which the user can implement custom hooks. + """ + def __init__(self, subtype: str, *args, **kwargs): + """ + :param subtype: This is the only mandatory attribute for this event type. It should be a string that + unambiguously identifies a certain type of event (like ``DISHWASHER_STARTED`` or ``SMOKE_DETECTED``). + :param args: Extra list arguments for the event. + :param kwargs: Extra key-value arguments for the event. + """ + super().__init__(*args, subtype=subtype, **kwargs) + + +# vim:sw=4:ts=4:et: