From df3d82e0e35b40308905e350c22b6572e62bf433 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Wed, 7 Nov 2018 09:03:35 +0100 Subject: [PATCH] Use async_add_executor_job at the xiaomi_miio platforms (#18294) --- .../components/device_tracker/xiaomi_miio.py | 3 ++- homeassistant/components/fan/xiaomi_miio.py | 11 ++++++----- homeassistant/components/light/xiaomi_miio.py | 17 +++++++++-------- homeassistant/components/remote/xiaomi_miio.py | 6 +++--- homeassistant/components/sensor/xiaomi_miio.py | 2 +- homeassistant/components/switch/xiaomi_miio.py | 11 ++++++----- homeassistant/components/vacuum/xiaomi_miio.py | 3 ++- 7 files changed, 29 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/device_tracker/xiaomi_miio.py b/homeassistant/components/device_tracker/xiaomi_miio.py index 1c02efe4489..1abd86ffd8a 100644 --- a/homeassistant/components/device_tracker/xiaomi_miio.py +++ b/homeassistant/components/device_tracker/xiaomi_miio.py @@ -61,7 +61,8 @@ class XiaomiMiioDeviceScanner(DeviceScanner): devices = [] try: - station_info = await self.hass.async_add_job(self.device.status) + station_info = \ + await self.hass.async_add_executor_job(self.device.status) _LOGGER.debug("Got new station info: %s", station_info) for device in station_info.associated_stations: diff --git a/homeassistant/components/fan/xiaomi_miio.py b/homeassistant/components/fan/xiaomi_miio.py index dab7f2ab9c3..3462b0bc1eb 100644 --- a/homeassistant/components/fan/xiaomi_miio.py +++ b/homeassistant/components/fan/xiaomi_miio.py @@ -51,7 +51,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ 'zhimi.airpurifier.mc1', 'zhimi.humidifier.v1', 'zhimi.humidifier.ca1', - 'zhimi.airfresh.va2']), + 'zhimi.airfresh.va2', + ]), }) ATTR_MODEL = 'model' @@ -494,7 +495,7 @@ class XiaomiGenericDevice(FanEntity): """Call a miio device command handling error messages.""" from miio import DeviceException try: - result = await self.hass.async_add_job( + result = await self.hass.async_add_executor_job( partial(func, *args, **kwargs)) _LOGGER.debug("Response received from miio device: %s", result) @@ -598,7 +599,7 @@ class XiaomiAirPurifier(XiaomiGenericDevice): return try: - state = await self.hass.async_add_job( + state = await self.hass.async_add_executor_job( self._device.status) _LOGGER.debug("Got new state: %s", state) @@ -774,7 +775,7 @@ class XiaomiAirHumidifier(XiaomiGenericDevice): return try: - state = await self.hass.async_add_job(self._device.status) + state = await self.hass.async_add_executor_job(self._device.status) _LOGGER.debug("Got new state: %s", state) self._available = True @@ -877,7 +878,7 @@ class XiaomiAirFresh(XiaomiGenericDevice): return try: - state = await self.hass.async_add_job( + state = await self.hass.async_add_executor_job( self._device.status) _LOGGER.debug("Got new state: %s", state) diff --git a/homeassistant/components/light/xiaomi_miio.py b/homeassistant/components/light/xiaomi_miio.py index cc88dbfe29f..291d8eaa267 100644 --- a/homeassistant/components/light/xiaomi_miio.py +++ b/homeassistant/components/light/xiaomi_miio.py @@ -41,7 +41,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ 'philips.light.bulb', 'philips.light.candle', 'philips.light.candle2', - 'philips.light.mono1']), + 'philips.light.mono1', + ]), }) # The light does not accept cct values < 1 @@ -263,7 +264,7 @@ class XiaomiPhilipsAbstractLight(Light): """Call a light command handling error messages.""" from miio import DeviceException try: - result = await self.hass.async_add_job( + result = await self.hass.async_add_executor_job( partial(func, *args, **kwargs)) _LOGGER.debug("Response received from light: %s", result) @@ -303,7 +304,7 @@ class XiaomiPhilipsAbstractLight(Light): """Fetch state from the device.""" from miio import DeviceException try: - state = await self.hass.async_add_job(self._light.status) + state = await self.hass.async_add_executor_job(self._light.status) _LOGGER.debug("Got new state: %s", state) self._available = True @@ -331,7 +332,7 @@ class XiaomiPhilipsGenericLight(XiaomiPhilipsAbstractLight): """Fetch state from the device.""" from miio import DeviceException try: - state = await self.hass.async_add_job(self._light.status) + state = await self.hass.async_add_executor_job(self._light.status) _LOGGER.debug("Got new state: %s", state) self._available = True @@ -481,7 +482,7 @@ class XiaomiPhilipsBulb(XiaomiPhilipsGenericLight): """Fetch state from the device.""" from miio import DeviceException try: - state = await self.hass.async_add_job(self._light.status) + state = await self.hass.async_add_executor_job(self._light.status) _LOGGER.debug("Got new state: %s", state) self._available = True @@ -541,7 +542,7 @@ class XiaomiPhilipsCeilingLamp(XiaomiPhilipsBulb): """Fetch state from the device.""" from miio import DeviceException try: - state = await self.hass.async_add_job(self._light.status) + state = await self.hass.async_add_executor_job(self._light.status) _LOGGER.debug("Got new state: %s", state) self._available = True @@ -587,7 +588,7 @@ class XiaomiPhilipsEyecareLamp(XiaomiPhilipsGenericLight): """Fetch state from the device.""" from miio import DeviceException try: - state = await self.hass.async_add_job(self._light.status) + state = await self.hass.async_add_executor_job(self._light.status) _LOGGER.debug("Got new state: %s", state) self._available = True @@ -715,7 +716,7 @@ class XiaomiPhilipsEyecareLampAmbientLight(XiaomiPhilipsAbstractLight): """Fetch state from the device.""" from miio import DeviceException try: - state = await self.hass.async_add_job(self._light.status) + state = await self.hass.async_add_executor_job(self._light.status) _LOGGER.debug("Got new state: %s", state) self._available = True diff --git a/homeassistant/components/remote/xiaomi_miio.py b/homeassistant/components/remote/xiaomi_miio.py index 0f63357c0dc..915f38745a4 100644 --- a/homeassistant/components/remote/xiaomi_miio.py +++ b/homeassistant/components/remote/xiaomi_miio.py @@ -128,14 +128,14 @@ async def async_setup_platform(hass, config, async_add_entities, slot = service.data.get(CONF_SLOT, entity.slot) - await hass.async_add_job(device.learn, slot) + await hass.async_add_executor_job(device.learn, slot) timeout = service.data.get(CONF_TIMEOUT, entity.timeout) _LOGGER.info("Press the key you want Home Assistant to learn") start_time = utcnow() while (utcnow() - start_time) < timedelta(seconds=timeout): - message = await hass.async_add_job( + message = await hass.async_add_executor_job( device.read, slot) _LOGGER.debug("Message received from device: '%s'", message) @@ -148,7 +148,7 @@ async def async_setup_platform(hass, config, async_add_entities, if ('error' in message and message['error']['message'] == "learn timeout"): - await hass.async_add_job(device.learn, slot) + await hass.async_add_executor_job(device.learn, slot) await asyncio.sleep(1, loop=hass.loop) diff --git a/homeassistant/components/sensor/xiaomi_miio.py b/homeassistant/components/sensor/xiaomi_miio.py index 86ee2f8767c..dddf7b23922 100644 --- a/homeassistant/components/sensor/xiaomi_miio.py +++ b/homeassistant/components/sensor/xiaomi_miio.py @@ -142,7 +142,7 @@ class XiaomiAirQualityMonitor(Entity): from miio import DeviceException try: - state = await self.hass.async_add_job(self._device.status) + state = await self.hass.async_add_executor_job(self._device.status) _LOGGER.debug("Got new state: %s", state) self._available = True diff --git a/homeassistant/components/switch/xiaomi_miio.py b/homeassistant/components/switch/xiaomi_miio.py index d55b2301745..7e11f986b92 100644 --- a/homeassistant/components/switch/xiaomi_miio.py +++ b/homeassistant/components/switch/xiaomi_miio.py @@ -38,7 +38,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ 'zimi.powerstrip.v2', 'chuangmi.plug.m1', 'chuangmi.plug.v2', - 'chuangmi.plug.v3']), + 'chuangmi.plug.v3', + ]), }) ATTR_POWER = 'power' @@ -247,7 +248,7 @@ class XiaomiPlugGenericSwitch(SwitchDevice): """Call a plug command handling error messages.""" from miio import DeviceException try: - result = await self.hass.async_add_job( + result = await self.hass.async_add_executor_job( partial(func, *args, **kwargs)) _LOGGER.debug("Response received from plug: %s", result) @@ -290,7 +291,7 @@ class XiaomiPlugGenericSwitch(SwitchDevice): return try: - state = await self.hass.async_add_job(self._plug.status) + state = await self.hass.async_add_executor_job(self._plug.status) _LOGGER.debug("Got new state: %s", state) self._available = True @@ -366,7 +367,7 @@ class XiaomiPowerStripSwitch(XiaomiPlugGenericSwitch): return try: - state = await self.hass.async_add_job(self._plug.status) + state = await self.hass.async_add_executor_job(self._plug.status) _LOGGER.debug("Got new state: %s", state) self._available = True @@ -463,7 +464,7 @@ class ChuangMiPlugSwitch(XiaomiPlugGenericSwitch): return try: - state = await self.hass.async_add_job(self._plug.status) + state = await self.hass.async_add_executor_job(self._plug.status) _LOGGER.debug("Got new state: %s", state) self._available = True diff --git a/homeassistant/components/vacuum/xiaomi_miio.py b/homeassistant/components/vacuum/xiaomi_miio.py index 2e25af36b11..a491b69ca2f 100644 --- a/homeassistant/components/vacuum/xiaomi_miio.py +++ b/homeassistant/components/vacuum/xiaomi_miio.py @@ -266,7 +266,8 @@ class MiroboVacuum(StateVacuumDevice): """Call a vacuum command handling error messages.""" from miio import DeviceException try: - await self.hass.async_add_job(partial(func, *args, **kwargs)) + await self.hass.async_add_executor_job( + partial(func, *args, **kwargs)) return True except DeviceException as exc: _LOGGER.error(mask_error, exc)