Sanity check to prevent empty objects from being propagated to sensor.transform_entities

This commit is contained in:
Fabio Manganiello 2023-04-01 23:41:28 +02:00
parent 3f3726c50a
commit 99572f9731
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -335,6 +335,14 @@ class SensorPlugin(RunnablePlugin, SensorEntityManager, ABC):
def publish_entities( def publish_entities(
self, entities: SensorDataType, *args, **kwargs self, entities: SensorDataType, *args, **kwargs
) -> Collection[Entity]: ) -> Collection[Entity]:
# Skip empty data
if (
entities is None
or (isinstance(entities, dict) and not entities)
or (isinstance(entities, (list, tuple)) and not entities)
):
return []
return super().publish_entities(entities, *args, **kwargs) # type: ignore return super().publish_entities(entities, *args, **kwargs) # type: ignore
@abstractmethod @abstractmethod