Added support for heart rate sensor entities.

This commit is contained in:
Fabio Manganiello 2023-02-23 00:55:55 +01:00
parent 3dab94c346
commit c3e16f9f9d
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
4 changed files with 34 additions and 0 deletions

View file

@ -135,6 +135,14 @@
}
},
"heart_rate_sensor": {
"name": "Sensor",
"name_plural": "Sensors",
"icon": {
"class": "fas fa-heart-pulse"
}
},
"muted": {
"name": "Switch",
"name_plural": "Switches",

View file

@ -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__,
}

View file

@ -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', '%'),