Added an abstract base SensorDataEvent for sensor events.

This commit is contained in:
Fabio Manganiello 2023-03-31 22:51:35 +02:00
parent 6a3ade3304
commit bf75eb73ac
Signed by: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -1,49 +1,41 @@
from abc import ABC
from typing import Optional from typing import Optional
from platypush.common.sensors import SensorDataType
from platypush.message.event import Event 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 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) class SensorDataAboveThresholdEvent(SensorDataEvent):
self.data = data
self.source = source
class SensorDataAboveThresholdEvent(Event):
""" """
Event triggered when a sensor's read goes above a configured threshold 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) class SensorDataBelowThresholdEvent(SensorDataEvent):
self.data = data
class SensorDataBelowThresholdEvent(Event):
""" """
Event triggered when a sensor's read goes below a configured threshold 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: # vim:sw=4:ts=4:et: