From b1399f34101eaffa7b3af1c5f8f4653dc35d51d7 Mon Sep 17 00:00:00 2001 From: Mike Chou Date: Fri, 2 Aug 2024 23:49:57 +0800 Subject: [PATCH] fix vibration sensor not reset --- custom_components/aqara_gateway/binary_sensor.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/custom_components/aqara_gateway/binary_sensor.py b/custom_components/aqara_gateway/binary_sensor.py index 04bb969..10d7ef6 100755 --- a/custom_components/aqara_gateway/binary_sensor.py +++ b/custom_components/aqara_gateway/binary_sensor.py @@ -159,6 +159,10 @@ def update(self, data: dict = None): self._state = not value self.schedule_update_ha_state() + + def reset_state(self): + self._state = '' + self.async_write_ha_state() class GatewayMotionSensor(GatewayBinarySensor): @@ -598,10 +602,6 @@ def update(self, data: dict = None): self.schedule_update_ha_state() - def reset_state(self): - self._state = '' - self.async_write_ha_state() - class GatewayAction(GatewayBinarySensor, BinarySensorEntity): """ Xiaomi/Aqara Action Cube """ @@ -714,9 +714,8 @@ def update(self, data: dict = None): 'entity_id': self.entity_id, 'click_type': self._state }) - time.sleep(.1) - - self._state = '' + # reset the state to empty after 0.1 second + self.hass.loop.call_later(.1, self.reset_state) self.schedule_update_ha_state()