From a0556d3a42c0694938bea2aa02eaeb18d4b6062b Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 23 Feb 2023 01:42:26 +0100 Subject: [PATCH] Added `PresenceSensor` entities. --- .../panels/Entities/PresenceSensor.vue | 1 + .../src/components/panels/Entities/meta.json | 8 +++++++ platypush/entities/presence.py | 23 +++++++++++++++++++ platypush/plugins/bluetooth/ble/_mappers.py | 3 +++ 4 files changed, 35 insertions(+) create mode 120000 platypush/backend/http/webapp/src/components/panels/Entities/PresenceSensor.vue create mode 100644 platypush/entities/presence.py diff --git a/platypush/backend/http/webapp/src/components/panels/Entities/PresenceSensor.vue b/platypush/backend/http/webapp/src/components/panels/Entities/PresenceSensor.vue new file mode 120000 index 0000000000..70b944608e --- /dev/null +++ b/platypush/backend/http/webapp/src/components/panels/Entities/PresenceSensor.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 24685c5c08..ca10b9a727 100644 --- a/platypush/backend/http/webapp/src/components/panels/Entities/meta.json +++ b/platypush/backend/http/webapp/src/components/panels/Entities/meta.json @@ -111,6 +111,14 @@ } }, + "presence_sensor": { + "name": "Sensor", + "name_plural": "Sensors", + "icon": { + "class": "fas fa-person" + } + }, + "link_quality": { "name": "Link Quality", "name_plural": "Link Qualities", diff --git a/platypush/entities/presence.py b/platypush/entities/presence.py new file mode 100644 index 0000000000..19ae9c6f4b --- /dev/null +++ b/platypush/entities/presence.py @@ -0,0 +1,23 @@ +from sqlalchemy import Column, Integer, ForeignKey + +from platypush.common.db import Base + +from .sensors import BinarySensor + + +if 'presence_sensor' not in Base.metadata: + + class PressureSensor(BinarySensor): + """ + A binary sensor that detects presence. + """ + + __tablename__ = 'presence_sensor' + + id = Column( + Integer, ForeignKey(BinarySensor.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 0f2ff5d613..4145437d8e 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 DewPointSensor, HumiditySensor from platypush.entities.illuminance import IlluminanceSensor from platypush.entities.motion import MotionSensor +from platypush.entities.presence import PresenceSensor from platypush.entities.pressure import PressureSensor from platypush.entities.sensors import BinarySensor, NumericSensor, RawSensor from platypush.entities.steps import StepsSensor @@ -84,6 +85,7 @@ _property_to_entity: Dict[str, Callable[[Any, Dict[str, Any]], Entity]] = { value=value, unit=conf.get('unit', 'kWh'), ), + 'heart rate': lambda value, _: HeartRateSensor(value=value), 'humidity': lambda value, conf: HumiditySensor( value=value, unit=conf.get('unit', '%'), @@ -103,6 +105,7 @@ _property_to_entity: Dict[str, Callable[[Any, Dict[str, Any]], Entity]] = { value=value, unit=conf.get('unit', 'W'), ), + 'presence': lambda value, _: PresenceSensor(value=value), 'pressure': lambda value, conf: PressureSensor( value=value, unit=conf.get('unit'),