From 4d27f4be51d3325f29a71d7b2bf7809fe3d615c6 Mon Sep 17 00:00:00 2001 From: YogevBokobza Date: Wed, 27 Mar 2024 17:15:49 +0200 Subject: [PATCH] Refactor switcher kis (#114281) * switcher: small refactoring * swithcer: Update switch.py * more refactoring * fix ruff --- homeassistant/components/switcher_kis/cover.py | 2 +- homeassistant/components/switcher_kis/switch.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/switcher_kis/cover.py b/homeassistant/components/switcher_kis/cover.py index 88a3b5050d9..69ec501c4a7 100644 --- a/homeassistant/components/switcher_kis/cover.py +++ b/homeassistant/components/switcher_kis/cover.py @@ -126,6 +126,6 @@ class SwitcherCoverEntity( """Move the cover to a specific position.""" await self._async_call_api(API_SET_POSITON, kwargs[ATTR_POSITION]) - async def async_stop_cover(self, **_kwargs: Any) -> None: + async def async_stop_cover(self, **kwargs: Any) -> None: """Stop the cover.""" await self._async_call_api(API_STOP) diff --git a/homeassistant/components/switcher_kis/switch.py b/homeassistant/components/switcher_kis/switch.py index ba5291d6ec0..b7c79f6dbc3 100644 --- a/homeassistant/components/switcher_kis/switch.py +++ b/homeassistant/components/switcher_kis/switch.py @@ -34,6 +34,9 @@ from .const import ( _LOGGER = logging.getLogger(__name__) +API_CONTROL_DEVICE = "control_device" +API_SET_AUTO_SHUTDOWN = "set_auto_shutdown" + SERVICE_SET_AUTO_OFF_SCHEMA = { vol.Required(CONF_AUTO_OFF): cv.time_period_str, } @@ -141,13 +144,13 @@ class SwitcherBaseSwitchEntity( async def async_turn_on(self, **kwargs: Any) -> None: """Turn the entity on.""" - await self._async_call_api("control_device", Command.ON) + await self._async_call_api(API_CONTROL_DEVICE, Command.ON) self.control_result = True self.async_write_ha_state() async def async_turn_off(self, **kwargs: Any) -> None: """Turn the entity off.""" - await self._async_call_api("control_device", Command.OFF) + await self._async_call_api(API_CONTROL_DEVICE, Command.OFF) self.control_result = False self.async_write_ha_state() @@ -181,11 +184,11 @@ class SwitcherWaterHeaterSwitchEntity(SwitcherBaseSwitchEntity): async def async_set_auto_off_service(self, auto_off: timedelta) -> None: """Use for handling setting device auto-off service calls.""" - await self._async_call_api("set_auto_shutdown", auto_off) + await self._async_call_api(API_SET_AUTO_SHUTDOWN, auto_off) self.async_write_ha_state() async def async_turn_on_with_timer_service(self, timer_minutes: int) -> None: """Use for turning device on with a timer service calls.""" - await self._async_call_api("control_device", Command.ON, timer_minutes) + await self._async_call_api(API_CONTROL_DEVICE, Command.ON, timer_minutes) self.control_result = True self.async_write_ha_state()