From d21227624719b834785b5afda7a21e6c5d9cdb4e Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 23 Feb 2023 01:12:27 +0100 Subject: [PATCH] Added `PressureSensor` entities. --- .../panels/Entities/PressureSensor.vue | 1 + .../src/components/panels/Entities/meta.json | 8 +++++++ platypush/entities/pressure.py | 23 +++++++++++++++++++ platypush/plugins/bluetooth/ble/_mappers.py | 13 +++++++++-- 4 files changed, 43 insertions(+), 2 deletions(-) create mode 120000 platypush/backend/http/webapp/src/components/panels/Entities/PressureSensor.vue create mode 100644 platypush/entities/pressure.py diff --git a/platypush/backend/http/webapp/src/components/panels/Entities/PressureSensor.vue b/platypush/backend/http/webapp/src/components/panels/Entities/PressureSensor.vue new file mode 120000 index 0000000000..70b944608e --- /dev/null +++ b/platypush/backend/http/webapp/src/components/panels/Entities/PressureSensor.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 87e7c157a7..d82f8eecdc 100644 --- a/platypush/backend/http/webapp/src/components/panels/Entities/meta.json +++ b/platypush/backend/http/webapp/src/components/panels/Entities/meta.json @@ -151,6 +151,14 @@ } }, + "pressure_sensor": { + "name": "Sensor", + "name_plural": "Sensors", + "icon": { + "class": "fas fa-gauge" + } + }, + "muted": { "name": "Switch", "name_plural": "Switches", diff --git a/platypush/entities/pressure.py b/platypush/entities/pressure.py new file mode 100644 index 0000000000..d52767b89e --- /dev/null +++ b/platypush/entities/pressure.py @@ -0,0 +1,23 @@ +from sqlalchemy import Column, Integer, ForeignKey + +from platypush.common.db import Base + +from .sensors import NumericSensor + + +if 'pressure_sensor' not in Base.metadata: + + class PressureSensor(NumericSensor): + """ + A sensor that measures pressure. + """ + + __tablename__ = 'pressure_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 4ce1ffcb8d..f1d4fde86d 100644 --- a/platypush/plugins/bluetooth/ble/_mappers.py +++ b/platypush/plugins/bluetooth/ble/_mappers.py @@ -24,6 +24,7 @@ from platypush.entities.heart import HeartRateSensor from platypush.entities.humidity import HumiditySensor from platypush.entities.illuminance import IlluminanceSensor from platypush.entities.motion import MotionSensor +from platypush.entities.pressure import PressureSensor from platypush.entities.sensors import BinarySensor, NumericSensor, RawSensor from platypush.entities.steps import StepsSensor from platypush.entities.temperature import TemperatureSensor @@ -81,12 +82,20 @@ _property_to_entity: Dict[str, Callable[[Any, Dict[str, Any]], Entity]] = { min=conf.get('min', 0), max=conf.get('min', 100), ), - 'light level': lambda value, _: IlluminanceSensor(value=value), + 'light level': lambda value, conf: IlluminanceSensor( + value=value, + unit=conf.get('unit'), + ), + 'luminance': lambda value, conf: IlluminanceSensor( + value=value, + unit=conf.get('unit'), + ), + 'motion': lambda value, _: MotionSensor(value=value), 'power': lambda value, conf: PowerSensor( value=value, unit=conf.get('unit', 'W'), ), - 'motion': lambda value, _: MotionSensor(value=value), + 'pressure': lambda value, _: PressureSensor(value=value), 'steps': lambda value, _: StepsSensor(value=value), 'temperature': lambda value, conf: TemperatureSensor( value=value,