From 99572f9731964730d074770611623324608ad703 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 1 Apr 2023 23:41:28 +0200 Subject: [PATCH] Sanity check to prevent empty objects from being propagated to `sensor.transform_entities` --- platypush/plugins/sensor/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/platypush/plugins/sensor/__init__.py b/platypush/plugins/sensor/__init__.py index 923c1570af..d6dc8c76fe 100644 --- a/platypush/plugins/sensor/__init__.py +++ b/platypush/plugins/sensor/__init__.py @@ -335,6 +335,14 @@ class SensorPlugin(RunnablePlugin, SensorEntityManager, ABC): def publish_entities( self, entities: SensorDataType, *args, **kwargs ) -> 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 @abstractmethod