Sfoglia il codice sorgente

device: pass full_poll to entity.on_receive so event entities can use it.

full_poll was popped off from the data before calling on_receive, so
was not available for event to determine when the last value could be
cleared.

Make it available explicitly as a separate argument to on_receive.

Issue #1818
Jason Rumney 1 anno fa
parent
commit
a83858af0f

+ 1 - 1
custom_components/tuya_local/device.py

@@ -209,7 +209,7 @@ class TuyaLocalDevice(object):
 
                     for entity in self._children:
                         # let entities trigger off poll contents directly
-                        entity.on_receive(poll)
+                        entity.on_receive(poll, full_poll)
                         # clear non-persistant dps that were not in a full poll
                         if full_poll:
                             for dp in entity._config.dps():

+ 3 - 3
custom_components/tuya_local/event.py

@@ -55,14 +55,14 @@ class TuyaLocalEvent(TuyaLocalEntity, EventEntity):
         # Set up event_types via parent class attribute
         self._attr_event_types = self._event_dp.values(device)
 
-    def on_receive(self, dps):
+    def on_receive(self, dps, full_poll):
         """Trigger the event when dp is received"""
         if self._event_dp.id in dps:
             value = self._event_dp.get_value(self._device)
             if value is not None:
                 # filter out full polls pulling the current ongoing value,
                 # but limit this to allow repeats to come through on non-full polls
-                if value == self._last_value and dps["full_poll"]:
+                if value == self._last_value and full_poll:
                     _LOGGER.debug(
                         "%s/%s value %s is the same as last value, ignoring",
                         self._config._device.config,
@@ -83,7 +83,7 @@ class TuyaLocalEvent(TuyaLocalEntity, EventEntity):
                 )
             # clear out the remembered value when a full poll comes through
             # with nothing
-            elif value is None and dps["full_poll"]:
+            elif value is None and full_poll:
                 _LOGGER.debug(
                     "%s/%s clearing last value due to no value in full poll",
                     self._config._device.config,

+ 1 - 1
custom_components/tuya_local/helpers/mixin.py

@@ -110,7 +110,7 @@ class TuyaLocalEntity:
     async def async_will_remove_from_hass(self):
         await self._device.async_unregister_entity(self)
 
-    def on_receive(self, dps):
+    def on_receive(self, dps, full_poll):
         """Override to process dps directly as they are received"""
         pass