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 000000000..ee0a9cbab --- /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 93de899fb..1fae044a4 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 3b57e02db..0542c01f1 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: