Implemented meta property for entities (for now it only include icon_class)

This commit is contained in:
Fabio Manganiello 2022-04-07 18:09:25 +02:00
parent e40b668380
commit db7c2095ea
Signed by: blacklight
GPG key ID: D90FBA7F76362774
4 changed files with 30 additions and 1 deletions

View file

@ -51,6 +51,13 @@ class Entity(Base):
'polymorphic_on': type, 'polymorphic_on': type,
} }
@classmethod
@property
def meta(cls) -> Mapping:
return {
'icon_class': 'fa-solid fa-circle-question',
}
@classmethod @classmethod
@property @property
def columns(cls) -> Tuple[ColumnProperty]: def columns(cls) -> Tuple[ColumnProperty]:
@ -66,7 +73,10 @@ class Entity(Base):
return val return val
def to_json(self) -> dict: 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): def get_plugin(self):
from platypush.context import get_plugin from platypush.context import get_plugin

View file

@ -12,3 +12,9 @@ class Device(Entity):
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
@classmethod
@property
def meta(cls):
return {
'icon_class': 'fa-solid fa-gear',
}

View file

@ -12,3 +12,9 @@ class Light(Device):
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
@classmethod
@property
def meta(cls):
return {
'icon_class': 'fa-solid fa-lightbulb',
}

View file

@ -13,6 +13,13 @@ class Switch(Device):
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }
@classmethod
@property
def meta(cls):
return {
'icon_class': 'fa-solid fa-light-switch',
}
def on(self): def on(self):
return self.get_plugin().on(self) return self.get_plugin().on(self)