diff --git a/platypush/backend/http/webapp/src/components/panels/Entities/TimeDurationSensor.vue b/platypush/backend/http/webapp/src/components/panels/Entities/TimeDurationSensor.vue new file mode 120000 index 000000000..70b944608 --- /dev/null +++ b/platypush/backend/http/webapp/src/components/panels/Entities/TimeDurationSensor.vue @@ -0,0 +1 @@ +Sensor.vue \ No newline at end of file diff --git a/platypush/backend/http/webapp/src/components/panels/Entities/meta.json b/platypush/backend/http/webapp/src/components/panels/Entities/meta.json index 8d20a9305..87e7c157a 100644 --- a/platypush/backend/http/webapp/src/components/panels/Entities/meta.json +++ b/platypush/backend/http/webapp/src/components/panels/Entities/meta.json @@ -143,6 +143,14 @@ } }, + "time_duration_sensor": { + "name": "Sensor", + "name_plural": "Sensors", + "icon": { + "class": "fas fa-clock" + } + }, + "muted": { "name": "Switch", "name_plural": "Switches", diff --git a/platypush/entities/time.py b/platypush/entities/time.py new file mode 100644 index 000000000..b6d3c0032 --- /dev/null +++ b/platypush/entities/time.py @@ -0,0 +1,23 @@ +from sqlalchemy import Column, Integer, ForeignKey + +from platypush.common.db import Base + +from .sensors import NumericSensor + + +if 'time_duration_sensor' not in Base.metadata: + + class TimeDurationSensor(NumericSensor): + """ + A sensor that measures a time duration. + """ + + __tablename__ = 'time_duration_sensor' + + id = Column( + Integer, ForeignKey(NumericSensor.id, ondelete='CASCADE'), primary_key=True + ) + + __mapper_args__ = { + 'polymorphic_identity': __tablename__, + } diff --git a/platypush/plugins/bluetooth/ble/_mappers.py b/platypush/plugins/bluetooth/ble/_mappers.py index 2ebf3809e..a8be0ef08 100644 --- a/platypush/plugins/bluetooth/ble/_mappers.py +++ b/platypush/plugins/bluetooth/ble/_mappers.py @@ -27,6 +27,7 @@ from platypush.entities.motion import MotionSensor from platypush.entities.sensors import BinarySensor, NumericSensor, RawSensor from platypush.entities.steps import StepsSensor from platypush.entities.temperature import TemperatureSensor +from platypush.entities.time import TimeDurationSensor @dataclass @@ -55,6 +56,7 @@ class NullSensor: # Maps property names to transformer methods (first mapper choice). _property_to_entity: Dict[str, Callable[[Any, Dict[str, Any]], Entity]] = { + 'activity heart rate': lambda value, _: HeartRateSensor(value=value), 'battery': lambda value, conf: Battery( value=value, unit=conf.get('unit', '%'), @@ -65,11 +67,14 @@ _property_to_entity: Dict[str, Callable[[Any, Dict[str, Any]], Entity]] = { value=value, unit=conf.get('unit', 'A'), ), + 'duration': lambda value, conf: TimeDurationSensor( + value=value, + unit=conf.get('unit'), + ), 'energy': lambda value, conf: EnergySensor( value=value, unit=conf.get('unit', 'kWh'), ), - 'activity heart rate': lambda value, _: HeartRateSensor(value=value), 'humidity': lambda value, conf: HumiditySensor( value=value, unit=conf.get('unit', '%'),