diff --git a/platypush/backend/http/webapp/src/components/panels/Entities/Accelerometer.vue b/platypush/backend/http/webapp/src/components/panels/Entities/Accelerometer.vue new file mode 120000 index 000000000..70b944608 --- /dev/null +++ b/platypush/backend/http/webapp/src/components/panels/Entities/Accelerometer.vue @@ -0,0 +1 @@ +Sensor.vue \ No newline at end of file diff --git a/platypush/backend/http/webapp/src/components/panels/Entities/Magnetometer.vue b/platypush/backend/http/webapp/src/components/panels/Entities/Magnetometer.vue new file mode 120000 index 000000000..70b944608 --- /dev/null +++ b/platypush/backend/http/webapp/src/components/panels/Entities/Magnetometer.vue @@ -0,0 +1 @@ +Sensor.vue \ No newline at end of file diff --git a/platypush/backend/http/webapp/src/components/panels/Entities/ThreeAxisSensor.vue b/platypush/backend/http/webapp/src/components/panels/Entities/ThreeAxisSensor.vue new file mode 120000 index 000000000..70b944608 --- /dev/null +++ b/platypush/backend/http/webapp/src/components/panels/Entities/ThreeAxisSensor.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 5a94f9c38..9df02b289 100644 --- a/platypush/backend/http/webapp/src/components/panels/Entities/meta.json +++ b/platypush/backend/http/webapp/src/components/panels/Entities/meta.json @@ -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", diff --git a/platypush/entities/acceleration.py b/platypush/entities/acceleration.py new file mode 100644 index 000000000..c7112ae78 --- /dev/null +++ b/platypush/entities/acceleration.py @@ -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__, + } diff --git a/platypush/entities/magnetism.py b/platypush/entities/magnetism.py new file mode 100644 index 000000000..1e464ba98 --- /dev/null +++ b/platypush/entities/magnetism.py @@ -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__, + } diff --git a/platypush/entities/three_axis.py b/platypush/entities/three_axis.py new file mode 100644 index 000000000..2758dfa80 --- /dev/null +++ b/platypush/entities/three_axis.py @@ -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