From db7c2095eaceff1baa80689a52192550574283c1 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 7 Apr 2022 18:09:25 +0200 Subject: [PATCH] Implemented meta property for entities (for now it only include `icon_class`) --- platypush/entities/_base.py | 12 +++++++++++- platypush/entities/devices.py | 6 ++++++ platypush/entities/lights.py | 6 ++++++ platypush/entities/switches.py | 7 +++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/platypush/entities/_base.py b/platypush/entities/_base.py index 98e9bdcd0..3de25334c 100644 --- a/platypush/entities/_base.py +++ b/platypush/entities/_base.py @@ -51,6 +51,13 @@ class Entity(Base): 'polymorphic_on': type, } + @classmethod + @property + def meta(cls) -> Mapping: + return { + 'icon_class': 'fa-solid fa-circle-question', + } + @classmethod @property def columns(cls) -> Tuple[ColumnProperty]: @@ -66,7 +73,10 @@ class Entity(Base): return val def to_json(self) -> dict: - return {col.key: self._serialize_value(col) for col in self.columns} + return { + **{col.key: self._serialize_value(col) for col in self.columns}, + 'meta': self.meta, + } def get_plugin(self): from platypush.context import get_plugin diff --git a/platypush/entities/devices.py b/platypush/entities/devices.py index dfc64f01f..f5d596cb9 100644 --- a/platypush/entities/devices.py +++ b/platypush/entities/devices.py @@ -12,3 +12,9 @@ class Device(Entity): 'polymorphic_identity': __tablename__, } + @classmethod + @property + def meta(cls): + return { + 'icon_class': 'fa-solid fa-gear', + } diff --git a/platypush/entities/lights.py b/platypush/entities/lights.py index 95f303f90..a571e8698 100644 --- a/platypush/entities/lights.py +++ b/platypush/entities/lights.py @@ -12,3 +12,9 @@ class Light(Device): 'polymorphic_identity': __tablename__, } + @classmethod + @property + def meta(cls): + return { + 'icon_class': 'fa-solid fa-lightbulb', + } diff --git a/platypush/entities/switches.py b/platypush/entities/switches.py index ebae03e53..8f01350b6 100644 --- a/platypush/entities/switches.py +++ b/platypush/entities/switches.py @@ -13,6 +13,13 @@ class Switch(Device): 'polymorphic_identity': __tablename__, } + @classmethod + @property + def meta(cls): + return { + 'icon_class': 'fa-solid fa-light-switch', + } + def on(self): return self.get_plugin().on(self)