diff --git a/platypush/backend/http/webapp/src/components/panels/Entities/ContactSensor.vue b/platypush/backend/http/webapp/src/components/panels/Entities/ContactSensor.vue new file mode 120000 index 000000000..b00126b9d --- /dev/null +++ b/platypush/backend/http/webapp/src/components/panels/Entities/ContactSensor.vue @@ -0,0 +1 @@ +BinarySensor.vue \ No newline at end of file diff --git a/platypush/backend/http/webapp/src/components/panels/Entities/PresenceSensor.vue b/platypush/backend/http/webapp/src/components/panels/Entities/PresenceSensor.vue index 70b944608..b00126b9d 120000 --- a/platypush/backend/http/webapp/src/components/panels/Entities/PresenceSensor.vue +++ b/platypush/backend/http/webapp/src/components/panels/Entities/PresenceSensor.vue @@ -1 +1 @@ -Sensor.vue \ No newline at end of file +BinarySensor.vue \ No newline at end of file diff --git a/platypush/backend/http/webapp/src/components/panels/Entities/WeightSensor.vue b/platypush/backend/http/webapp/src/components/panels/Entities/WeightSensor.vue new file mode 120000 index 000000000..70b944608 --- /dev/null +++ b/platypush/backend/http/webapp/src/components/panels/Entities/WeightSensor.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 ca10b9a72..b484f8871 100644 --- a/platypush/backend/http/webapp/src/components/panels/Entities/meta.json +++ b/platypush/backend/http/webapp/src/components/panels/Entities/meta.json @@ -111,6 +111,14 @@ } }, + "contact_sensor": { + "name": "Sensor", + "name_plural": "Sensors", + "icon": { + "class": "far fa-hand" + } + }, + "presence_sensor": { "name": "Sensor", "name_plural": "Sensors", @@ -119,6 +127,14 @@ } }, + "weight_sensor": { + "name": "Sensor", + "name_plural": "Sensors", + "icon": { + "class": "fas fa-weight-scale" + } + }, + "link_quality": { "name": "Link Quality", "name_plural": "Link Qualities", diff --git a/platypush/entities/contact.py b/platypush/entities/contact.py new file mode 100644 index 000000000..00b502b58 --- /dev/null +++ b/platypush/entities/contact.py @@ -0,0 +1,23 @@ +from sqlalchemy import Column, Integer, ForeignKey + +from platypush.common.db import Base + +from .sensors import BinarySensor + + +if 'contact_sensor' not in Base.metadata: + + class ContactSensor(BinarySensor): + """ + A binary sensor that detects contact. + """ + + __tablename__ = 'contact_sensor' + + id = Column( + Integer, ForeignKey(BinarySensor.id, ondelete='CASCADE'), primary_key=True + ) + + __mapper_args__ = { + 'polymorphic_identity': __tablename__, + } diff --git a/platypush/entities/presence.py b/platypush/entities/presence.py index 19ae9c6f4..334bc4c43 100644 --- a/platypush/entities/presence.py +++ b/platypush/entities/presence.py @@ -7,7 +7,7 @@ from .sensors import BinarySensor if 'presence_sensor' not in Base.metadata: - class PressureSensor(BinarySensor): + class PresenceSensor(BinarySensor): """ A binary sensor that detects presence. """ diff --git a/platypush/entities/weight.py b/platypush/entities/weight.py new file mode 100644 index 000000000..37cbe4f45 --- /dev/null +++ b/platypush/entities/weight.py @@ -0,0 +1,23 @@ +from sqlalchemy import Column, Integer, ForeignKey + +from platypush.common.db import Base + +from .sensors import NumericSensor + + +if 'weight_sensor' not in Base.metadata: + + class WeightSensor(NumericSensor): + """ + A sensor that measures weight. + """ + + __tablename__ = 'weight_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 4145437d8..974513568 100644 --- a/platypush/plugins/bluetooth/ble/_mappers.py +++ b/platypush/plugins/bluetooth/ble/_mappers.py @@ -14,6 +14,7 @@ from TheengsGateway._decoder import decodeBLE, getAttribute, getProperties from platypush.entities import Entity from platypush.entities.batteries import Battery from platypush.entities.bluetooth import BluetoothDevice +from platypush.entities.contact import ContactSensor from platypush.entities.electricity import ( CurrentSensor, EnergySensor, @@ -30,6 +31,7 @@ from platypush.entities.sensors import BinarySensor, NumericSensor, RawSensor from platypush.entities.steps import StepsSensor from platypush.entities.temperature import TemperatureSensor from platypush.entities.time import TimeDurationSensor +from platypush.entities.weight import WeightSensor @dataclass @@ -69,6 +71,7 @@ _property_to_entity: Dict[str, Callable[[Any, Dict[str, Any]], Entity]] = { min=conf.get('min', 0), max=conf.get('min', 100), ), + 'contact': lambda value, _: ContactSensor(value=value), 'current': lambda value, conf: CurrentSensor( value=value, unit=conf.get('unit', 'A'), @@ -100,7 +103,12 @@ _property_to_entity: Dict[str, Callable[[Any, Dict[str, Any]], Entity]] = { value=value, unit=conf.get('unit'), ), + 'moisture': lambda value, conf: HumiditySensor( + value=value, + unit=conf.get('unit'), + ), 'motion': lambda value, _: MotionSensor(value=value), + 'open': lambda value, _: BinarySensor(value=value), 'power': lambda value, conf: PowerSensor( value=value, unit=conf.get('unit', 'W'), @@ -143,10 +151,18 @@ _property_to_entity: Dict[str, Callable[[Any, Dict[str, Any]], Entity]] = { value=value, unit=conf.get('unit', 'C'), ), + 'volt': lambda value, conf: VoltageSensor( + value=value, + unit=conf.get('unit', 'V'), + ), 'voltage': lambda value, conf: VoltageSensor( value=value, unit=conf.get('unit', 'V'), ), + 'weight': lambda value, conf: WeightSensor( + value=value, + unit=conf.get('unit', 'kg'), + ), } # Maps reported units to transformer methods (second mapper choice).