Update fan to use async_add_executor_job (#41457)

This commit is contained in:
J. Nick Koston 2020-10-08 02:21:29 -05:00 committed by GitHub
parent e10413fa4c
commit 1bf6166817
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -117,7 +117,7 @@ class FanEntity(ToggleEntity):
if speed == SPEED_OFF: if speed == SPEED_OFF:
await self.async_turn_off() await self.async_turn_off()
else: else:
await self.hass.async_add_job(self.set_speed, speed) await self.hass.async_add_executor_job(self.set_speed, speed)
def set_direction(self, direction: str) -> None: def set_direction(self, direction: str) -> None:
"""Set the direction of the fan.""" """Set the direction of the fan."""
@ -125,7 +125,7 @@ class FanEntity(ToggleEntity):
async def async_set_direction(self, direction: str): async def async_set_direction(self, direction: str):
"""Set the direction of the fan.""" """Set the direction of the fan."""
await self.hass.async_add_job(self.set_direction, direction) await self.hass.async_add_executor_job(self.set_direction, direction)
# pylint: disable=arguments-differ # pylint: disable=arguments-differ
def turn_on(self, speed: Optional[str] = None, **kwargs) -> None: def turn_on(self, speed: Optional[str] = None, **kwargs) -> None:
@ -138,14 +138,16 @@ class FanEntity(ToggleEntity):
if speed == SPEED_OFF: if speed == SPEED_OFF:
await self.async_turn_off() await self.async_turn_off()
else: else:
await self.hass.async_add_job(ft.partial(self.turn_on, speed, **kwargs)) await self.hass.async_add_executor_job(
ft.partial(self.turn_on, speed, **kwargs)
)
def oscillate(self, oscillating: bool) -> None: def oscillate(self, oscillating: bool) -> None:
"""Oscillate the fan.""" """Oscillate the fan."""
async def async_oscillate(self, oscillating: bool): async def async_oscillate(self, oscillating: bool):
"""Oscillate the fan.""" """Oscillate the fan."""
await self.hass.async_add_job(self.oscillate, oscillating) await self.hass.async_add_executor_job(self.oscillate, oscillating)
@property @property
def is_on(self): def is_on(self):