forked from platypush/platypush
Added an abstract base SensorDataEvent
for sensor events.
This commit is contained in:
parent
6a3ade3304
commit
bf75eb73ac
1 changed files with 20 additions and 28 deletions
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue