forked from platypush/platypush
Added 3-axis sensor, accelerometer and magnetometer entities
This commit is contained in:
parent
d964167631
commit
5a6f4bcf57
7 changed files with 107 additions and 0 deletions
|
@ -0,0 +1 @@
|
|||
Sensor.vue
|
|
@ -0,0 +1 @@
|
|||
Sensor.vue
|
|
@ -0,0 +1 @@
|
|||
Sensor.vue
|
|
@ -63,6 +63,22 @@
|
|||
}
|
||||
},
|
||||
|
||||
"accelerometer": {
|
||||
"name": "Sensor",
|
||||
"name_plural": "Sensors",
|
||||
"icon": {
|
||||
"class": "fas fa-up-down-left-right"
|
||||
}
|
||||
},
|
||||
|
||||
"magnetometer": {
|
||||
"name": "Sensor",
|
||||
"name_plural": "Sensors",
|
||||
"icon": {
|
||||
"class": "fas fa-magnet"
|
||||
}
|
||||
},
|
||||
|
||||
"device": {
|
||||
"name": "Device",
|
||||
"name_plural": "Devices",
|
||||
|
|
25
platypush/entities/acceleration.py
Normal file
25
platypush/entities/acceleration.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
from sqlalchemy import Column, Integer, ForeignKey
|
||||
|
||||
from platypush.common.db import Base
|
||||
|
||||
from .three_axis import ThreeAxisSensor
|
||||
|
||||
|
||||
if 'accelerometer' not in Base.metadata:
|
||||
|
||||
class Accelerometer(ThreeAxisSensor):
|
||||
"""
|
||||
An entity that represents the value of an accelerometer sensor.
|
||||
"""
|
||||
|
||||
__tablename__ = 'accelerometer'
|
||||
|
||||
id = Column(
|
||||
Integer,
|
||||
ForeignKey(ThreeAxisSensor.id, ondelete='CASCADE'),
|
||||
primary_key=True,
|
||||
)
|
||||
|
||||
__mapper_args__ = {
|
||||
'polymorphic_identity': __tablename__,
|
||||
}
|
25
platypush/entities/magnetism.py
Normal file
25
platypush/entities/magnetism.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
from sqlalchemy import Column, Integer, ForeignKey
|
||||
|
||||
from platypush.common.db import Base
|
||||
|
||||
from .three_axis import ThreeAxisSensor
|
||||
|
||||
|
||||
if 'magnetometer' not in Base.metadata:
|
||||
|
||||
class Magnetometer(ThreeAxisSensor):
|
||||
"""
|
||||
An entity that represents the value of a magnetometer.
|
||||
"""
|
||||
|
||||
__tablename__ = 'magnetometer'
|
||||
|
||||
id = Column(
|
||||
Integer,
|
||||
ForeignKey(ThreeAxisSensor.id, ondelete='CASCADE'),
|
||||
primary_key=True,
|
||||
)
|
||||
|
||||
__mapper_args__ = {
|
||||
'polymorphic_identity': __tablename__,
|
||||
}
|
38
platypush/entities/three_axis.py
Normal file
38
platypush/entities/three_axis.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
from sqlalchemy import Column, Integer, ForeignKey
|
||||
from sqlalchemy.orm import reconstructor, validates
|
||||
|
||||
from platypush.common.db import Base
|
||||
|
||||
from .sensors import RawSensor
|
||||
|
||||
|
||||
if 'three_axis_sensor' not in Base.metadata:
|
||||
|
||||
class ThreeAxisSensor(RawSensor):
|
||||
"""
|
||||
An entity that measures a time duration.
|
||||
"""
|
||||
|
||||
__tablename__ = 'three_axis_sensor'
|
||||
|
||||
id = Column(
|
||||
Integer, ForeignKey(RawSensor.id, ondelete='CASCADE'), primary_key=True
|
||||
)
|
||||
|
||||
__mapper_args__ = {
|
||||
'polymorphic_identity': __tablename__,
|
||||
}
|
||||
|
||||
@validates('_value')
|
||||
def check_value(self, _, value):
|
||||
assert (
|
||||
isinstance('_value', (list, tuple))
|
||||
and len(value) == 3
|
||||
and all(isinstance(v, (int, float)) for v in value)
|
||||
), f'Invalid 3-axis value: {value}'
|
||||
|
||||
return list(value)
|
||||
|
||||
@reconstructor
|
||||
def post_init(self):
|
||||
self.is_json = True
|
Loading…
Reference in a new issue