From bf75eb73acdfd59e4a2ffd6611c0859c097ef26e Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Fri, 31 Mar 2023 22:51:35 +0200 Subject: [PATCH] Added an abstract base `SensorDataEvent` for sensor events. --- platypush/message/event/sensor/__init__.py | 48 +++++++++------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/platypush/message/event/sensor/__init__.py b/platypush/message/event/sensor/__init__.py index b10672eee0..7a011d9968 100644 --- a/platypush/message/event/sensor/__init__.py +++ b/platypush/message/event/sensor/__init__.py @@ -1,49 +1,41 @@ +from abc import ABC from typing import Optional +from platypush.common.sensors import SensorDataType from platypush.message.event import Event -class SensorDataChangeEvent(Event): +class SensorDataEvent(Event, ABC): + """ + Sensor events base class. + """ + + def __init__( + self, *args, data: SensorDataType, source: Optional[str] = None, **kwargs + ): + """ + :param data: Sensor data. + :param source: Sensor source - usually the plugin qualified name. + """ + super().__init__(data=data, source=source, *args, **kwargs) + + +class SensorDataChangeEvent(SensorDataEvent): """ Event triggered when a sensor has new data """ - def __init__(self, data, source: Optional[str] = None, *args, **kwargs): - """ - :param data: Sensor data - """ - super().__init__(data=data, source=source, *args, **kwargs) - self.data = data - self.source = source - - -class SensorDataAboveThresholdEvent(Event): +class SensorDataAboveThresholdEvent(SensorDataEvent): """ Event triggered when a sensor's read goes above a configured threshold """ - def __init__(self, data, *args, **kwargs): - """ - :param data: Sensor data - """ - super().__init__(data=data, *args, **kwargs) - self.data = data - - -class SensorDataBelowThresholdEvent(Event): +class SensorDataBelowThresholdEvent(SensorDataEvent): """ Event triggered when a sensor's read goes below a configured threshold """ - def __init__(self, data, *args, **kwargs): - """ - :param data: Sensor data - """ - - super().__init__(data=data, *args, **kwargs) - self.data = data - # vim:sw=4:ts=4:et: