Added DewPointSensor entities.

This commit is contained in:
Fabio Manganiello 2023-02-23 01:23:04 +01:00
parent d212276247
commit 56d693032a
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
4 changed files with 43 additions and 4 deletions

View file

@ -0,0 +1 @@
Sensor.vue

View file

@ -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",

View file

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

View file

@ -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()
}