Use async_add_executor_job at the xiaomi_miio platforms (#18294)

This commit is contained in:
Sebastian Muszynski 2018-11-07 09:03:35 +01:00 committed by GitHub
parent 35ae85e14e
commit df3d82e0e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 24 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)