From 65481dc6b4198b5da5a15401226a4ca1ab9f5206 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 17 Apr 2023 02:08:15 +0200 Subject: [PATCH] Added `PercentSensor` entity type. --- .../panels/Entities/PercentSensor.vue | 52 +++++++++++++++++++ .../src/components/panels/Entities/meta.json | 8 +++ platypush/entities/sensors.py | 23 +++++++- 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 platypush/backend/http/webapp/src/components/panels/Entities/PercentSensor.vue diff --git a/platypush/backend/http/webapp/src/components/panels/Entities/PercentSensor.vue b/platypush/backend/http/webapp/src/components/panels/Entities/PercentSensor.vue new file mode 100644 index 00000000..ee0a9cba --- /dev/null +++ b/platypush/backend/http/webapp/src/components/panels/Entities/PercentSensor.vue @@ -0,0 +1,52 @@ + + + + + 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 93de899f..1fae044a 100644 --- a/platypush/backend/http/webapp/src/components/panels/Entities/meta.json +++ b/platypush/backend/http/webapp/src/components/panels/Entities/meta.json @@ -295,6 +295,14 @@ } }, + "percent_sensor": { + "name": "Sensor", + "name_plural": "Sensors", + "icon": { + "class": "fas fa-thermometer" + } + }, + "enum_sensor": { "name": "Sensor", "name_plural": "Sensors", diff --git a/platypush/entities/sensors.py b/platypush/entities/sensors.py index 3b57e02d..0542c01f 100644 --- a/platypush/entities/sensors.py +++ b/platypush/entities/sensors.py @@ -91,7 +91,7 @@ if 'raw_sensor' not in Base.metadata: } -if 'numeric_sensor' not in Base.metadata: +if 'numeric_sensor' not in Base.metadata and 'percent_sensor' not in Base.metadata: class NumericSensor(Sensor): """ @@ -113,6 +113,27 @@ if 'numeric_sensor' not in Base.metadata: 'polymorphic_identity': __tablename__, } + class PercentSensor(NumericSensor): + """ + A subclass of ``NumericSensor`` that represents a percentage value. + """ + + __tablename__ = 'percent_sensor' + + id = Column( + Integer, ForeignKey(NumericSensor.id, ondelete='CASCADE'), primary_key=True + ) + + __mapper_args__ = { + 'polymorphic_identity': __tablename__, + } + + def __init__(self, *args, **kwargs): + self.min = 0.0 + self.max = 1.0 + self.unit = '%' + super().__init__(*args, **kwargs) + if 'binary_sensor' not in Base.metadata: