Added remaining bluetooth entity types in _mappers.py.

This commit is contained in:
Fabio Manganiello 2023-02-23 21:20:41 +01:00
parent a0556d3a42
commit 2dfb389630
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
8 changed files with 82 additions and 2 deletions

View file

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

View file

@ -1 +1 @@
Sensor.vue BinarySensor.vue

View file

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

View file

@ -111,6 +111,14 @@
} }
}, },
"contact_sensor": {
"name": "Sensor",
"name_plural": "Sensors",
"icon": {
"class": "far fa-hand"
}
},
"presence_sensor": { "presence_sensor": {
"name": "Sensor", "name": "Sensor",
"name_plural": "Sensors", "name_plural": "Sensors",
@ -119,6 +127,14 @@
} }
}, },
"weight_sensor": {
"name": "Sensor",
"name_plural": "Sensors",
"icon": {
"class": "fas fa-weight-scale"
}
},
"link_quality": { "link_quality": {
"name": "Link Quality", "name": "Link Quality",
"name_plural": "Link Qualities", "name_plural": "Link Qualities",

View file

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

View file

@ -7,7 +7,7 @@ from .sensors import BinarySensor
if 'presence_sensor' not in Base.metadata: if 'presence_sensor' not in Base.metadata:
class PressureSensor(BinarySensor): class PresenceSensor(BinarySensor):
""" """
A binary sensor that detects presence. A binary sensor that detects presence.
""" """

View file

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

View file

@ -14,6 +14,7 @@ from TheengsGateway._decoder import decodeBLE, getAttribute, getProperties
from platypush.entities import Entity from platypush.entities import Entity
from platypush.entities.batteries import Battery from platypush.entities.batteries import Battery
from platypush.entities.bluetooth import BluetoothDevice from platypush.entities.bluetooth import BluetoothDevice
from platypush.entities.contact import ContactSensor
from platypush.entities.electricity import ( from platypush.entities.electricity import (
CurrentSensor, CurrentSensor,
EnergySensor, EnergySensor,
@ -30,6 +31,7 @@ from platypush.entities.sensors import BinarySensor, NumericSensor, RawSensor
from platypush.entities.steps import StepsSensor from platypush.entities.steps import StepsSensor
from platypush.entities.temperature import TemperatureSensor from platypush.entities.temperature import TemperatureSensor
from platypush.entities.time import TimeDurationSensor from platypush.entities.time import TimeDurationSensor
from platypush.entities.weight import WeightSensor
@dataclass @dataclass
@ -69,6 +71,7 @@ _property_to_entity: Dict[str, Callable[[Any, Dict[str, Any]], Entity]] = {
min=conf.get('min', 0), min=conf.get('min', 0),
max=conf.get('min', 100), max=conf.get('min', 100),
), ),
'contact': lambda value, _: ContactSensor(value=value),
'current': lambda value, conf: CurrentSensor( 'current': lambda value, conf: CurrentSensor(
value=value, value=value,
unit=conf.get('unit', 'A'), unit=conf.get('unit', 'A'),
@ -100,7 +103,12 @@ _property_to_entity: Dict[str, Callable[[Any, Dict[str, Any]], Entity]] = {
value=value, value=value,
unit=conf.get('unit'), unit=conf.get('unit'),
), ),
'moisture': lambda value, conf: HumiditySensor(
value=value,
unit=conf.get('unit'),
),
'motion': lambda value, _: MotionSensor(value=value), 'motion': lambda value, _: MotionSensor(value=value),
'open': lambda value, _: BinarySensor(value=value),
'power': lambda value, conf: PowerSensor( 'power': lambda value, conf: PowerSensor(
value=value, value=value,
unit=conf.get('unit', 'W'), unit=conf.get('unit', 'W'),
@ -143,10 +151,18 @@ _property_to_entity: Dict[str, Callable[[Any, Dict[str, Any]], Entity]] = {
value=value, value=value,
unit=conf.get('unit', 'C'), unit=conf.get('unit', 'C'),
), ),
'volt': lambda value, conf: VoltageSensor(
value=value,
unit=conf.get('unit', 'V'),
),
'voltage': lambda value, conf: VoltageSensor( 'voltage': lambda value, conf: VoltageSensor(
value=value, value=value,
unit=conf.get('unit', 'V'), 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). # Maps reported units to transformer methods (second mapper choice).