Преглед изворни кода

event: don't re-trigger events when a value continues to repeat

Some devices maintain a value in every full poll (every 30s) even though
it is not a new event.  Filter these out, but ensure that if a full_poll
comes through empty, it is cleared to the same event can be repeated when
it really is a repeat.

Issue #1818
Jason Rumney пре 1 година
родитељ
комит
405b63a171
1 измењених фајлова са 10 додато и 0 уклоњено
  1. 10 0
      custom_components/tuya_local/event.py

+ 10 - 0
custom_components/tuya_local/event.py

@@ -39,6 +39,7 @@ class TuyaLocalEvent(TuyaLocalEntity, EventEntity):
         dps_map = self._init_begin(device, config)
         self._event_dp = dps_map.pop("event")
         self._init_end(dps_map)
+        self._last_value = None
 
         # Set up device_class via parent class attribute
         try:
@@ -59,7 +60,16 @@ class TuyaLocalEvent(TuyaLocalEntity, EventEntity):
         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"]:
+                    return
+                self._last_value = value
                 self._trigger_event(
                     value,
                     self.extra_state_attributes,
                 )
+            # clear out the remembered value when a full poll comes through
+            # with nothing
+            elif value is None and dps["full_poll"]:
+                self._last_value = None