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 00000000..70b94460 --- /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 d82f8eec..24685c5c 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 ecafe351..8672d8fd 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 f1d4fde8..24ea81ae 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() }