From c3e16f9f9d3230b6df4fea6f474a91af34b6c72c Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 23 Feb 2023 00:55:55 +0100 Subject: [PATCH] Added support for heart rate sensor entities. --- .../panels/Entities/HeartRateSensor.vue | 1 + .../src/components/panels/Entities/meta.json | 8 +++++++ platypush/entities/heart.py | 23 +++++++++++++++++++ platypush/plugins/bluetooth/ble/_mappers.py | 2 ++ 4 files changed, 34 insertions(+) create mode 120000 platypush/backend/http/webapp/src/components/panels/Entities/HeartRateSensor.vue create mode 100644 platypush/entities/heart.py diff --git a/platypush/backend/http/webapp/src/components/panels/Entities/HeartRateSensor.vue b/platypush/backend/http/webapp/src/components/panels/Entities/HeartRateSensor.vue new file mode 120000 index 0000000000..70b944608e --- /dev/null +++ b/platypush/backend/http/webapp/src/components/panels/Entities/HeartRateSensor.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 6dd1046000..8d20a9305e 100644 --- a/platypush/backend/http/webapp/src/components/panels/Entities/meta.json +++ b/platypush/backend/http/webapp/src/components/panels/Entities/meta.json @@ -135,6 +135,14 @@ } }, + "heart_rate_sensor": { + "name": "Sensor", + "name_plural": "Sensors", + "icon": { + "class": "fas fa-heart-pulse" + } + }, + "muted": { "name": "Switch", "name_plural": "Switches", diff --git a/platypush/entities/heart.py b/platypush/entities/heart.py new file mode 100644 index 0000000000..3c9e3067c3 --- /dev/null +++ b/platypush/entities/heart.py @@ -0,0 +1,23 @@ +from sqlalchemy import Column, Integer, ForeignKey + +from platypush.common.db import Base + +from .sensors import NumericSensor + + +if 'heart_rate_sensor' not in Base.metadata: + + class HeartRateSensor(NumericSensor): + """ + A sensor that measures the heart rate. + """ + + __tablename__ = 'heart_rate_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 bad2504ec3..2ebf3809e2 100644 --- a/platypush/plugins/bluetooth/ble/_mappers.py +++ b/platypush/plugins/bluetooth/ble/_mappers.py @@ -20,6 +20,7 @@ from platypush.entities.electricity import ( PowerSensor, VoltageSensor, ) +from platypush.entities.heart import HeartRateSensor from platypush.entities.humidity import HumiditySensor from platypush.entities.illuminance import IlluminanceSensor from platypush.entities.motion import MotionSensor @@ -68,6 +69,7 @@ _property_to_entity: Dict[str, Callable[[Any, Dict[str, Any]], Entity]] = { 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', '%'),