From 56d693032acee68502339d302758123db27ac491 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 23 Feb 2023 01:23:04 +0100 Subject: [PATCH] Added `DewPointSensor` entities. --- .../panels/Entities/DewPointSensor.vue | 1 + .../src/components/panels/Entities/meta.json | 8 +++++++ platypush/entities/humidity.py | 22 +++++++++++++++++++ platypush/plugins/bluetooth/ble/_mappers.py | 16 ++++++++++---- 4 files changed, 43 insertions(+), 4 deletions(-) create mode 120000 platypush/backend/http/webapp/src/components/panels/Entities/DewPointSensor.vue diff --git a/platypush/backend/http/webapp/src/components/panels/Entities/DewPointSensor.vue b/platypush/backend/http/webapp/src/components/panels/Entities/DewPointSensor.vue new file mode 120000 index 0000000000..70b944608e --- /dev/null +++ b/platypush/backend/http/webapp/src/components/panels/Entities/DewPointSensor.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 d82f8eecdc..24685c5c08 100644 --- a/platypush/backend/http/webapp/src/components/panels/Entities/meta.json +++ b/platypush/backend/http/webapp/src/components/panels/Entities/meta.json @@ -87,6 +87,14 @@ } }, + "dew_point_sensor": { + "name": "Sensor", + "name_plural": "Sensors", + "icon": { + "class": "fas fa-hand-holding-droplet" + } + }, + "illuminance_sensor": { "name": "Sensor", "name_plural": "Sensors", diff --git a/platypush/entities/humidity.py b/platypush/entities/humidity.py index ecafe351e2..8672d8fd33 100644 --- a/platypush/entities/humidity.py +++ b/platypush/entities/humidity.py @@ -8,6 +8,10 @@ from .sensors import NumericSensor if 'humidity_sensor' not in Base.metadata: class HumiditySensor(NumericSensor): + """ + A sensor that measures humidity. + """ + __tablename__ = 'humidity_sensor' id = Column( @@ -17,3 +21,21 @@ if 'humidity_sensor' not in Base.metadata: __mapper_args__ = { 'polymorphic_identity': __tablename__, } + + +if 'dew_point_sensor' not in Base.metadata: + + class DewPointSensor(NumericSensor): + """ + A sensor that measures the dew point. + """ + + __tablename__ = 'dew_point_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 f1d4fde86d..24ea81ae7f 100644 --- a/platypush/plugins/bluetooth/ble/_mappers.py +++ b/platypush/plugins/bluetooth/ble/_mappers.py @@ -21,7 +21,7 @@ from platypush.entities.electricity import ( VoltageSensor, ) from platypush.entities.heart import HeartRateSensor -from platypush.entities.humidity import HumiditySensor +from platypush.entities.humidity import DewPointSensor, HumiditySensor from platypush.entities.illuminance import IlluminanceSensor from platypush.entities.motion import MotionSensor from platypush.entities.pressure import PressureSensor @@ -68,6 +68,10 @@ _property_to_entity: Dict[str, Callable[[Any, Dict[str, Any]], Entity]] = { value=value, unit=conf.get('unit', 'A'), ), + 'dew_point_sensor': lambda value, conf: DewPointSensor( + value=value, + unit=conf.get('unit'), + ), 'duration': lambda value, conf: TimeDurationSensor( value=value, unit=conf.get('unit'), @@ -95,7 +99,10 @@ _property_to_entity: Dict[str, Callable[[Any, Dict[str, Any]], Entity]] = { value=value, unit=conf.get('unit', 'W'), ), - 'pressure': lambda value, _: PressureSensor(value=value), + 'pressure': lambda value, conf: PressureSensor( + value=value, + unit=conf.get('unit'), + ), 'steps': lambda value, _: StepsSensor(value=value), 'temperature': lambda value, conf: TemperatureSensor( value=value, @@ -243,7 +250,7 @@ def parse_device_args(device: BLEDevice) -> Dict[str, Any]: object. """ - props = device.details.get('props', {}) + props = (device.details or {}).get('props', {}) return { 'name': device.name or device.address, 'connected': props.get('Connected', False), @@ -287,7 +294,8 @@ def _parse_service_data(device: BLEDevice) -> Dict[str, str]: """ return { service_uuid: ''.join([f'{x:02x}' for x in value]) - for service_uuid, value in device.details.get('props', {}) + for service_uuid, value in (device.details or {}) + .get('props', {}) .get('ServiceData', {}) .items() }