mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Use async_add_executor_job at the xiaomi_miio platforms (#18294)
This commit is contained in:
parent
35ae85e14e
commit
df3d82e0e3
@ -61,7 +61,8 @@ class XiaomiMiioDeviceScanner(DeviceScanner):
|
|||||||
|
|
||||||
devices = []
|
devices = []
|
||||||
try:
|
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)
|
_LOGGER.debug("Got new station info: %s", station_info)
|
||||||
|
|
||||||
for device in station_info.associated_stations:
|
for device in station_info.associated_stations:
|
||||||
|
@ -51,7 +51,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
'zhimi.airpurifier.mc1',
|
'zhimi.airpurifier.mc1',
|
||||||
'zhimi.humidifier.v1',
|
'zhimi.humidifier.v1',
|
||||||
'zhimi.humidifier.ca1',
|
'zhimi.humidifier.ca1',
|
||||||
'zhimi.airfresh.va2']),
|
'zhimi.airfresh.va2',
|
||||||
|
]),
|
||||||
})
|
})
|
||||||
|
|
||||||
ATTR_MODEL = 'model'
|
ATTR_MODEL = 'model'
|
||||||
@ -494,7 +495,7 @@ class XiaomiGenericDevice(FanEntity):
|
|||||||
"""Call a miio device command handling error messages."""
|
"""Call a miio device command handling error messages."""
|
||||||
from miio import DeviceException
|
from miio import DeviceException
|
||||||
try:
|
try:
|
||||||
result = await self.hass.async_add_job(
|
result = await self.hass.async_add_executor_job(
|
||||||
partial(func, *args, **kwargs))
|
partial(func, *args, **kwargs))
|
||||||
|
|
||||||
_LOGGER.debug("Response received from miio device: %s", result)
|
_LOGGER.debug("Response received from miio device: %s", result)
|
||||||
@ -598,7 +599,7 @@ class XiaomiAirPurifier(XiaomiGenericDevice):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
state = await self.hass.async_add_job(
|
state = await self.hass.async_add_executor_job(
|
||||||
self._device.status)
|
self._device.status)
|
||||||
_LOGGER.debug("Got new state: %s", state)
|
_LOGGER.debug("Got new state: %s", state)
|
||||||
|
|
||||||
@ -774,7 +775,7 @@ class XiaomiAirHumidifier(XiaomiGenericDevice):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
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)
|
_LOGGER.debug("Got new state: %s", state)
|
||||||
|
|
||||||
self._available = True
|
self._available = True
|
||||||
@ -877,7 +878,7 @@ class XiaomiAirFresh(XiaomiGenericDevice):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
state = await self.hass.async_add_job(
|
state = await self.hass.async_add_executor_job(
|
||||||
self._device.status)
|
self._device.status)
|
||||||
_LOGGER.debug("Got new state: %s", state)
|
_LOGGER.debug("Got new state: %s", state)
|
||||||
|
|
||||||
|
@ -41,7 +41,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
'philips.light.bulb',
|
'philips.light.bulb',
|
||||||
'philips.light.candle',
|
'philips.light.candle',
|
||||||
'philips.light.candle2',
|
'philips.light.candle2',
|
||||||
'philips.light.mono1']),
|
'philips.light.mono1',
|
||||||
|
]),
|
||||||
})
|
})
|
||||||
|
|
||||||
# The light does not accept cct values < 1
|
# The light does not accept cct values < 1
|
||||||
@ -263,7 +264,7 @@ class XiaomiPhilipsAbstractLight(Light):
|
|||||||
"""Call a light command handling error messages."""
|
"""Call a light command handling error messages."""
|
||||||
from miio import DeviceException
|
from miio import DeviceException
|
||||||
try:
|
try:
|
||||||
result = await self.hass.async_add_job(
|
result = await self.hass.async_add_executor_job(
|
||||||
partial(func, *args, **kwargs))
|
partial(func, *args, **kwargs))
|
||||||
|
|
||||||
_LOGGER.debug("Response received from light: %s", result)
|
_LOGGER.debug("Response received from light: %s", result)
|
||||||
@ -303,7 +304,7 @@ class XiaomiPhilipsAbstractLight(Light):
|
|||||||
"""Fetch state from the device."""
|
"""Fetch state from the device."""
|
||||||
from miio import DeviceException
|
from miio import DeviceException
|
||||||
try:
|
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)
|
_LOGGER.debug("Got new state: %s", state)
|
||||||
|
|
||||||
self._available = True
|
self._available = True
|
||||||
@ -331,7 +332,7 @@ class XiaomiPhilipsGenericLight(XiaomiPhilipsAbstractLight):
|
|||||||
"""Fetch state from the device."""
|
"""Fetch state from the device."""
|
||||||
from miio import DeviceException
|
from miio import DeviceException
|
||||||
try:
|
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)
|
_LOGGER.debug("Got new state: %s", state)
|
||||||
|
|
||||||
self._available = True
|
self._available = True
|
||||||
@ -481,7 +482,7 @@ class XiaomiPhilipsBulb(XiaomiPhilipsGenericLight):
|
|||||||
"""Fetch state from the device."""
|
"""Fetch state from the device."""
|
||||||
from miio import DeviceException
|
from miio import DeviceException
|
||||||
try:
|
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)
|
_LOGGER.debug("Got new state: %s", state)
|
||||||
|
|
||||||
self._available = True
|
self._available = True
|
||||||
@ -541,7 +542,7 @@ class XiaomiPhilipsCeilingLamp(XiaomiPhilipsBulb):
|
|||||||
"""Fetch state from the device."""
|
"""Fetch state from the device."""
|
||||||
from miio import DeviceException
|
from miio import DeviceException
|
||||||
try:
|
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)
|
_LOGGER.debug("Got new state: %s", state)
|
||||||
|
|
||||||
self._available = True
|
self._available = True
|
||||||
@ -587,7 +588,7 @@ class XiaomiPhilipsEyecareLamp(XiaomiPhilipsGenericLight):
|
|||||||
"""Fetch state from the device."""
|
"""Fetch state from the device."""
|
||||||
from miio import DeviceException
|
from miio import DeviceException
|
||||||
try:
|
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)
|
_LOGGER.debug("Got new state: %s", state)
|
||||||
|
|
||||||
self._available = True
|
self._available = True
|
||||||
@ -715,7 +716,7 @@ class XiaomiPhilipsEyecareLampAmbientLight(XiaomiPhilipsAbstractLight):
|
|||||||
"""Fetch state from the device."""
|
"""Fetch state from the device."""
|
||||||
from miio import DeviceException
|
from miio import DeviceException
|
||||||
try:
|
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)
|
_LOGGER.debug("Got new state: %s", state)
|
||||||
|
|
||||||
self._available = True
|
self._available = True
|
||||||
|
@ -128,14 +128,14 @@ async def async_setup_platform(hass, config, async_add_entities,
|
|||||||
|
|
||||||
slot = service.data.get(CONF_SLOT, entity.slot)
|
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)
|
timeout = service.data.get(CONF_TIMEOUT, entity.timeout)
|
||||||
|
|
||||||
_LOGGER.info("Press the key you want Home Assistant to learn")
|
_LOGGER.info("Press the key you want Home Assistant to learn")
|
||||||
start_time = utcnow()
|
start_time = utcnow()
|
||||||
while (utcnow() - start_time) < timedelta(seconds=timeout):
|
while (utcnow() - start_time) < timedelta(seconds=timeout):
|
||||||
message = await hass.async_add_job(
|
message = await hass.async_add_executor_job(
|
||||||
device.read, slot)
|
device.read, slot)
|
||||||
_LOGGER.debug("Message received from device: '%s'", message)
|
_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
|
if ('error' in message and
|
||||||
message['error']['message'] == "learn timeout"):
|
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)
|
await asyncio.sleep(1, loop=hass.loop)
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ class XiaomiAirQualityMonitor(Entity):
|
|||||||
from miio import DeviceException
|
from miio import DeviceException
|
||||||
|
|
||||||
try:
|
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)
|
_LOGGER.debug("Got new state: %s", state)
|
||||||
|
|
||||||
self._available = True
|
self._available = True
|
||||||
|
@ -38,7 +38,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
'zimi.powerstrip.v2',
|
'zimi.powerstrip.v2',
|
||||||
'chuangmi.plug.m1',
|
'chuangmi.plug.m1',
|
||||||
'chuangmi.plug.v2',
|
'chuangmi.plug.v2',
|
||||||
'chuangmi.plug.v3']),
|
'chuangmi.plug.v3',
|
||||||
|
]),
|
||||||
})
|
})
|
||||||
|
|
||||||
ATTR_POWER = 'power'
|
ATTR_POWER = 'power'
|
||||||
@ -247,7 +248,7 @@ class XiaomiPlugGenericSwitch(SwitchDevice):
|
|||||||
"""Call a plug command handling error messages."""
|
"""Call a plug command handling error messages."""
|
||||||
from miio import DeviceException
|
from miio import DeviceException
|
||||||
try:
|
try:
|
||||||
result = await self.hass.async_add_job(
|
result = await self.hass.async_add_executor_job(
|
||||||
partial(func, *args, **kwargs))
|
partial(func, *args, **kwargs))
|
||||||
|
|
||||||
_LOGGER.debug("Response received from plug: %s", result)
|
_LOGGER.debug("Response received from plug: %s", result)
|
||||||
@ -290,7 +291,7 @@ class XiaomiPlugGenericSwitch(SwitchDevice):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
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)
|
_LOGGER.debug("Got new state: %s", state)
|
||||||
|
|
||||||
self._available = True
|
self._available = True
|
||||||
@ -366,7 +367,7 @@ class XiaomiPowerStripSwitch(XiaomiPlugGenericSwitch):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
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)
|
_LOGGER.debug("Got new state: %s", state)
|
||||||
|
|
||||||
self._available = True
|
self._available = True
|
||||||
@ -463,7 +464,7 @@ class ChuangMiPlugSwitch(XiaomiPlugGenericSwitch):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
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)
|
_LOGGER.debug("Got new state: %s", state)
|
||||||
|
|
||||||
self._available = True
|
self._available = True
|
||||||
|
@ -266,7 +266,8 @@ class MiroboVacuum(StateVacuumDevice):
|
|||||||
"""Call a vacuum command handling error messages."""
|
"""Call a vacuum command handling error messages."""
|
||||||
from miio import DeviceException
|
from miio import DeviceException
|
||||||
try:
|
try:
|
||||||
await self.hass.async_add_job(partial(func, *args, **kwargs))
|
await self.hass.async_add_executor_job(
|
||||||
|
partial(func, *args, **kwargs))
|
||||||
return True
|
return True
|
||||||
except DeviceException as exc:
|
except DeviceException as exc:
|
||||||
_LOGGER.error(mask_error, exc)
|
_LOGGER.error(mask_error, exc)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user