From c1daa17dc7953c3f1212b5d80010e2dd08571c2c Mon Sep 17 00:00:00 2001 From: Pavel S Date: Sat, 21 Dec 2024 17:19:19 +0100 Subject: [PATCH] fix: async switch --- custom_components/mcp2221/switch.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/custom_components/mcp2221/switch.py b/custom_components/mcp2221/switch.py index 5d59d22..904eb46 100644 --- a/custom_components/mcp2221/switch.py +++ b/custom_components/mcp2221/switch.py @@ -94,7 +94,7 @@ async def async_added_to_hass(self) -> None: def is_on(self): return self._state - async def turn_on(self, **kwargs): + async def async_turn_on(self, **kwargs): LOGGER.info("Turn on GP%i", self._pin) try: async with self._lock: @@ -104,7 +104,9 @@ async def turn_on(self, **kwargs): LOGGER.error("Device not available") self._state = None - async def turn_off(self, **kwargs): + self.async_write_ha_state() + + async def async_turn_off(self, **kwargs): LOGGER.info("Turn off GP%i", self._pin) try: async with self._lock: @@ -113,3 +115,5 @@ async def turn_off(self, **kwargs): except OSError: LOGGER.error("Device not available") self._state = None + + self.async_write_ha_state()