Refactor switcher kis (#114281)

* switcher: small refactoring

* swithcer: Update switch.py

* more refactoring

* fix ruff
This commit is contained in:
YogevBokobza 2024-03-27 17:15:49 +02:00 committed by GitHub
parent c21d508c2d
commit 4d27f4be51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 5 deletions

View File

@ -126,6 +126,6 @@ class SwitcherCoverEntity(
"""Move the cover to a specific position.""" """Move the cover to a specific position."""
await self._async_call_api(API_SET_POSITON, kwargs[ATTR_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.""" """Stop the cover."""
await self._async_call_api(API_STOP) await self._async_call_api(API_STOP)

View File

@ -34,6 +34,9 @@ from .const import (
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
API_CONTROL_DEVICE = "control_device"
API_SET_AUTO_SHUTDOWN = "set_auto_shutdown"
SERVICE_SET_AUTO_OFF_SCHEMA = { SERVICE_SET_AUTO_OFF_SCHEMA = {
vol.Required(CONF_AUTO_OFF): cv.time_period_str, vol.Required(CONF_AUTO_OFF): cv.time_period_str,
} }
@ -141,13 +144,13 @@ class SwitcherBaseSwitchEntity(
async def async_turn_on(self, **kwargs: Any) -> None: async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the entity on.""" """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.control_result = True
self.async_write_ha_state() self.async_write_ha_state()
async def async_turn_off(self, **kwargs: Any) -> None: async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the entity off.""" """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.control_result = False
self.async_write_ha_state() self.async_write_ha_state()
@ -181,11 +184,11 @@ class SwitcherWaterHeaterSwitchEntity(SwitcherBaseSwitchEntity):
async def async_set_auto_off_service(self, auto_off: timedelta) -> None: async def async_set_auto_off_service(self, auto_off: timedelta) -> None:
"""Use for handling setting device auto-off service calls.""" """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() self.async_write_ha_state()
async def async_turn_on_with_timer_service(self, timer_minutes: int) -> None: async def async_turn_on_with_timer_service(self, timer_minutes: int) -> None:
"""Use for turning device on with a timer service calls.""" """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.control_result = True
self.async_write_ha_state() self.async_write_ha_state()