Added 3-axis sensor, accelerometer and magnetometer entities

This commit is contained in:
Fabio Manganiello 2023-04-02 01:13:22 +02:00
parent d964167631
commit 5a6f4bcf57
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
7 changed files with 107 additions and 0 deletions

View file

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

View file

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

View file

@ -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": { "device": {
"name": "Device", "name": "Device",
"name_plural": "Devices", "name_plural": "Devices",

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

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

View 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