Compare commits

...

3 Commits

Author SHA1 Message Date
epenet
13653cc10e Fix 2025-12-01 10:48:06 +00:00
epenet
810d437175 Simplify 2025-12-01 10:44:29 +00:00
epenet
b6ecc745ce Cleanup non-async Tuya command sender 2025-12-01 10:24:09 +00:00
3 changed files with 10 additions and 13 deletions

View File

@@ -61,14 +61,12 @@ class TuyaEntity(Entity):
) -> None:
self.async_write_ha_state()
def _send_command(self, commands: list[dict[str, Any]]) -> None:
"""Send command to the device."""
LOGGER.debug("Sending commands for device %s: %s", self.device.id, commands)
self.device_manager.send_commands(self.device.id, commands)
async def _async_send_commands(self, commands: list[dict[str, Any]]) -> None:
"""Send a list of commands to the device."""
await self.hass.async_add_executor_job(self._send_command, commands)
LOGGER.debug("Sending commands for device %s: %s", self.device.id, commands)
await self.hass.async_add_executor_job(
self.device_manager.send_commands, self.device.id, commands
)
def _read_wrapper(self, dpcode_wrapper: DPCodeWrapper | None) -> Any | None:
"""Read the wrapper device status."""
@@ -82,7 +80,6 @@ class TuyaEntity(Entity):
"""Send command to the device."""
if dpcode_wrapper is None:
return
await self.hass.async_add_executor_job(
self._send_command,
[dpcode_wrapper.get_update_command(self.device, value)],
await self._async_send_commands(
[dpcode_wrapper.get_update_command(self.device, value)]
)

View File

@@ -718,7 +718,7 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
"""Return true if light is on."""
return self._read_wrapper(self._switch_wrapper)
def turn_on(self, **kwargs: Any) -> None:
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on or control the light."""
commands = [
self._switch_wrapper.get_update_command(self.device, True),
@@ -780,7 +780,7 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
self._brightness_wrapper.get_update_command(self.device, brightness),
]
self._send_command(commands)
await self._async_send_commands(commands)
async def async_turn_off(self, **kwargs: Any) -> None:
"""Instruct the light to turn off."""

View File

@@ -196,7 +196,7 @@ class TuyaVacuumEntity(TuyaEntity, StateVacuumEntity):
"""Set fan speed."""
await self._async_send_dpcode_update(self._fan_speed_wrapper, fan_speed)
def send_command(
async def async_send_command(
self,
command: str,
params: dict[str, Any] | list[Any] | None = None,
@@ -207,4 +207,4 @@ class TuyaVacuumEntity(TuyaEntity, StateVacuumEntity):
raise ValueError("Params cannot be omitted for Tuya vacuum commands")
if not isinstance(params, list):
raise TypeError("Params must be a list for Tuya vacuum commands")
self._send_command([{"code": command, "value": params[0]}])
await self._async_send_commands([{"code": command, "value": params[0]}])