forked from platypush/platypush
Added remaining bluetooth
entity types in _mappers.py
.
This commit is contained in:
parent
a0556d3a42
commit
2dfb389630
8 changed files with 82 additions and 2 deletions
|
@ -0,0 +1 @@
|
|||
BinarySensor.vue
|
|
@ -1 +1 @@
|
|||
Sensor.vue
|
||||
BinarySensor.vue
|
|
@ -0,0 +1 @@
|
|||
Sensor.vue
|
|
@ -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",
|
||||
|
|
23
platypush/entities/contact.py
Normal file
23
platypush/entities/contact.py
Normal 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__,
|
||||
}
|
|
@ -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.
|
||||
"""
|
||||
|
|
23
platypush/entities/weight.py
Normal file
23
platypush/entities/weight.py
Normal 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__,
|
||||
}
|
|
@ -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).
|
||||
|
|
Loading…
Reference in a new issue