forked from platypush/platypush
variable.status
robustness fix.
`entities.transform_entities` will pass back an empty list instead of an empty dict if no entities were found, and the function should be able to handle it.
This commit is contained in:
parent
e919bf95ad
commit
23b851e9d7
1 changed files with 20 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
||||||
from typing import Collection, Dict, Optional
|
from typing import Collection, Dict, Iterable, Optional, Union
|
||||||
from typing_extensions import override
|
from typing_extensions import override
|
||||||
|
|
||||||
# from platypush.common.db import Base
|
# from platypush.common.db import Base
|
||||||
|
@ -115,22 +115,36 @@ class VariablePlugin(Plugin, EntityManager):
|
||||||
return self._redis.expire(name, expire)
|
return self._redis.expire(name, expire)
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def transform_entities(self, entities: dict) -> Collection[Variable]:
|
def transform_entities(
|
||||||
|
self, entities: Union[dict, Iterable]
|
||||||
|
) -> Collection[Variable]:
|
||||||
|
variables = (
|
||||||
|
[
|
||||||
|
{
|
||||||
|
'name': name,
|
||||||
|
'value': value,
|
||||||
|
}
|
||||||
|
for name, value in entities.items()
|
||||||
|
]
|
||||||
|
if isinstance(entities, dict)
|
||||||
|
else entities
|
||||||
|
)
|
||||||
|
|
||||||
return super().transform_entities(
|
return super().transform_entities(
|
||||||
[
|
[
|
||||||
Variable(id=name, name=name, value=value)
|
Variable(id=var['name'], name=var['name'], value=var['value'])
|
||||||
for name, value in entities.items()
|
for var in variables
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@action
|
@action
|
||||||
def status(self):
|
def status(self, *_, **__):
|
||||||
variables = {
|
variables = {
|
||||||
name: value for name, value in self._db_vars.items() if value is not None
|
name: value for name, value in self._db_vars.items() if value is not None
|
||||||
}
|
}
|
||||||
|
|
||||||
super().publish_entities(variables)
|
self.publish_entities(variables)
|
||||||
return variables
|
return variables
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue