mirror of
https://github.com/home-assistant/core
synced 2024-09-09 12:51:22 +02:00
Move imports in xiaomi_miio (#27773)
* move imports in xiaomi_miio * reorder imports with isort * fix pylint error * Rename imports
This commit is contained in:
parent
f2c56cff43
commit
f8d3ea20b6
@ -1,6 +1,7 @@
|
||||
"""Support for Xiaomi Mi WiFi Repeater 2."""
|
||||
import logging
|
||||
|
||||
from miio import DeviceException, WifiRepeater # pylint: disable=import-error
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.device_tracker import (
|
||||
@ -23,8 +24,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
||||
def get_scanner(hass, config):
|
||||
"""Return a Xiaomi MiIO device scanner."""
|
||||
from miio import WifiRepeater, DeviceException
|
||||
|
||||
scanner = None
|
||||
host = config[DOMAIN][CONF_HOST]
|
||||
token = config[DOMAIN][CONF_TOKEN]
|
||||
@ -56,8 +55,6 @@ class XiaomiMiioDeviceScanner(DeviceScanner):
|
||||
|
||||
async def async_scan_devices(self):
|
||||
"""Scan for devices and return a list containing found device IDs."""
|
||||
from miio import DeviceException
|
||||
|
||||
devices = []
|
||||
try:
|
||||
station_info = await self.hass.async_add_executor_job(self.device.status)
|
||||
|
@ -5,19 +5,39 @@ from functools import partial
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
from miio import ( # pylint: disable=import-error
|
||||
AirFresh,
|
||||
AirHumidifier,
|
||||
AirPurifier,
|
||||
Device,
|
||||
DeviceException,
|
||||
)
|
||||
|
||||
from miio.airfresh import ( # pylint: disable=import-error; pylint: disable=import-error
|
||||
LedBrightness as AirfreshLedBrightness,
|
||||
OperationMode as AirfreshOperationMode,
|
||||
)
|
||||
from miio.airhumidifier import ( # pylint: disable=import-error; pylint: disable=import-error
|
||||
LedBrightness as AirhumidifierLedBrightness,
|
||||
OperationMode as AirhumidifierOperationMode,
|
||||
)
|
||||
from miio.airpurifier import ( # pylint: disable=import-error; pylint: disable=import-error
|
||||
LedBrightness as AirpurifierLedBrightness,
|
||||
OperationMode as AirpurifierOperationMode,
|
||||
)
|
||||
|
||||
from homeassistant.components.fan import (
|
||||
FanEntity,
|
||||
DOMAIN,
|
||||
PLATFORM_SCHEMA,
|
||||
SUPPORT_SET_SPEED,
|
||||
DOMAIN,
|
||||
FanEntity,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_MODE,
|
||||
CONF_NAME,
|
||||
CONF_HOST,
|
||||
CONF_TOKEN,
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_MODE,
|
||||
CONF_HOST,
|
||||
CONF_NAME,
|
||||
CONF_TOKEN,
|
||||
)
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
@ -429,8 +449,6 @@ SERVICE_TO_METHOD = {
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the miio fan device from config."""
|
||||
from miio import Device, DeviceException
|
||||
|
||||
if DATA_KEY not in hass.data:
|
||||
hass.data[DATA_KEY] = {}
|
||||
|
||||
@ -458,18 +476,12 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
raise PlatformNotReady
|
||||
|
||||
if model.startswith("zhimi.airpurifier."):
|
||||
from miio import AirPurifier
|
||||
|
||||
air_purifier = AirPurifier(host, token)
|
||||
device = XiaomiAirPurifier(name, air_purifier, model, unique_id)
|
||||
elif model.startswith("zhimi.humidifier."):
|
||||
from miio import AirHumidifier
|
||||
|
||||
air_humidifier = AirHumidifier(host, token, model=model)
|
||||
device = XiaomiAirHumidifier(name, air_humidifier, model, unique_id)
|
||||
elif model.startswith("zhimi.airfresh."):
|
||||
from miio import AirFresh
|
||||
|
||||
air_fresh = AirFresh(host, token)
|
||||
device = XiaomiAirFresh(name, air_fresh, model, unique_id)
|
||||
else:
|
||||
@ -580,8 +592,6 @@ class XiaomiGenericDevice(FanEntity):
|
||||
|
||||
async def _try_command(self, mask_error, func, *args, **kwargs):
|
||||
"""Call a miio device command handling error messages."""
|
||||
from miio import DeviceException
|
||||
|
||||
try:
|
||||
result = await self.hass.async_add_executor_job(
|
||||
partial(func, *args, **kwargs)
|
||||
@ -698,8 +708,6 @@ class XiaomiAirPurifier(XiaomiGenericDevice):
|
||||
|
||||
async def async_update(self):
|
||||
"""Fetch state from the device."""
|
||||
from miio import DeviceException
|
||||
|
||||
# On state change the device doesn't provide the new state immediately.
|
||||
if self._skip_update:
|
||||
self._skip_update = False
|
||||
@ -731,9 +739,7 @@ class XiaomiAirPurifier(XiaomiGenericDevice):
|
||||
def speed(self):
|
||||
"""Return the current speed."""
|
||||
if self._state:
|
||||
from miio.airpurifier import OperationMode
|
||||
|
||||
return OperationMode(self._state_attrs[ATTR_MODE]).name
|
||||
return AirpurifierOperationMode(self._state_attrs[ATTR_MODE]).name
|
||||
|
||||
return None
|
||||
|
||||
@ -742,14 +748,12 @@ class XiaomiAirPurifier(XiaomiGenericDevice):
|
||||
if self.supported_features & SUPPORT_SET_SPEED == 0:
|
||||
return
|
||||
|
||||
from miio.airpurifier import OperationMode
|
||||
|
||||
_LOGGER.debug("Setting the operation mode to: %s", speed)
|
||||
|
||||
await self._try_command(
|
||||
"Setting operation mode of the miio device failed.",
|
||||
self._device.set_mode,
|
||||
OperationMode[speed.title()],
|
||||
AirpurifierOperationMode[speed.title()],
|
||||
)
|
||||
|
||||
async def async_set_led_on(self):
|
||||
@ -777,12 +781,10 @@ class XiaomiAirPurifier(XiaomiGenericDevice):
|
||||
if self._device_features & FEATURE_SET_LED_BRIGHTNESS == 0:
|
||||
return
|
||||
|
||||
from miio.airpurifier import LedBrightness
|
||||
|
||||
await self._try_command(
|
||||
"Setting the led brightness of the miio device failed.",
|
||||
self._device.set_led_brightness,
|
||||
LedBrightness(brightness),
|
||||
AirpurifierLedBrightness(brightness),
|
||||
)
|
||||
|
||||
async def async_set_favorite_level(self, level: int = 1):
|
||||
@ -878,21 +880,23 @@ class XiaomiAirHumidifier(XiaomiGenericDevice):
|
||||
|
||||
def __init__(self, name, device, model, unique_id):
|
||||
"""Initialize the plug switch."""
|
||||
from miio.airhumidifier import OperationMode
|
||||
|
||||
super().__init__(name, device, model, unique_id)
|
||||
|
||||
if self._model in [MODEL_AIRHUMIDIFIER_CA1, MODEL_AIRHUMIDIFIER_CB1]:
|
||||
self._device_features = FEATURE_FLAGS_AIRHUMIDIFIER_CA_AND_CB
|
||||
self._available_attributes = AVAILABLE_ATTRIBUTES_AIRHUMIDIFIER_CA_AND_CB
|
||||
self._speed_list = [
|
||||
mode.name for mode in OperationMode if mode is not OperationMode.Strong
|
||||
mode.name
|
||||
for mode in AirhumidifierOperationMode
|
||||
if mode is not AirhumidifierOperationMode.Strong
|
||||
]
|
||||
else:
|
||||
self._device_features = FEATURE_FLAGS_AIRHUMIDIFIER
|
||||
self._available_attributes = AVAILABLE_ATTRIBUTES_AIRHUMIDIFIER
|
||||
self._speed_list = [
|
||||
mode.name for mode in OperationMode if mode is not OperationMode.Auto
|
||||
mode.name
|
||||
for mode in AirhumidifierOperationMode
|
||||
if mode is not AirhumidifierOperationMode.Auto
|
||||
]
|
||||
|
||||
self._state_attrs.update(
|
||||
@ -901,8 +905,6 @@ class XiaomiAirHumidifier(XiaomiGenericDevice):
|
||||
|
||||
async def async_update(self):
|
||||
"""Fetch state from the device."""
|
||||
from miio import DeviceException
|
||||
|
||||
# On state change the device doesn't provide the new state immediately.
|
||||
if self._skip_update:
|
||||
self._skip_update = False
|
||||
@ -934,9 +936,7 @@ class XiaomiAirHumidifier(XiaomiGenericDevice):
|
||||
def speed(self):
|
||||
"""Return the current speed."""
|
||||
if self._state:
|
||||
from miio.airhumidifier import OperationMode
|
||||
|
||||
return OperationMode(self._state_attrs[ATTR_MODE]).name
|
||||
return AirhumidifierOperationMode(self._state_attrs[ATTR_MODE]).name
|
||||
|
||||
return None
|
||||
|
||||
@ -945,14 +945,12 @@ class XiaomiAirHumidifier(XiaomiGenericDevice):
|
||||
if self.supported_features & SUPPORT_SET_SPEED == 0:
|
||||
return
|
||||
|
||||
from miio.airhumidifier import OperationMode
|
||||
|
||||
_LOGGER.debug("Setting the operation mode to: %s", speed)
|
||||
|
||||
await self._try_command(
|
||||
"Setting operation mode of the miio device failed.",
|
||||
self._device.set_mode,
|
||||
OperationMode[speed.title()],
|
||||
AirhumidifierOperationMode[speed.title()],
|
||||
)
|
||||
|
||||
async def async_set_led_brightness(self, brightness: int = 2):
|
||||
@ -960,12 +958,10 @@ class XiaomiAirHumidifier(XiaomiGenericDevice):
|
||||
if self._device_features & FEATURE_SET_LED_BRIGHTNESS == 0:
|
||||
return
|
||||
|
||||
from miio.airhumidifier import LedBrightness
|
||||
|
||||
await self._try_command(
|
||||
"Setting the led brightness of the miio device failed.",
|
||||
self._device.set_led_brightness,
|
||||
LedBrightness(brightness),
|
||||
AirhumidifierLedBrightness(brightness),
|
||||
)
|
||||
|
||||
async def async_set_target_humidity(self, humidity: int = 40):
|
||||
@ -1018,8 +1014,6 @@ class XiaomiAirFresh(XiaomiGenericDevice):
|
||||
|
||||
async def async_update(self):
|
||||
"""Fetch state from the device."""
|
||||
from miio import DeviceException
|
||||
|
||||
# On state change the device doesn't provide the new state immediately.
|
||||
if self._skip_update:
|
||||
self._skip_update = False
|
||||
@ -1051,9 +1045,7 @@ class XiaomiAirFresh(XiaomiGenericDevice):
|
||||
def speed(self):
|
||||
"""Return the current speed."""
|
||||
if self._state:
|
||||
from miio.airfresh import OperationMode
|
||||
|
||||
return OperationMode(self._state_attrs[ATTR_MODE]).name
|
||||
return AirfreshOperationMode(self._state_attrs[ATTR_MODE]).name
|
||||
|
||||
return None
|
||||
|
||||
@ -1062,14 +1054,12 @@ class XiaomiAirFresh(XiaomiGenericDevice):
|
||||
if self.supported_features & SUPPORT_SET_SPEED == 0:
|
||||
return
|
||||
|
||||
from miio.airfresh import OperationMode
|
||||
|
||||
_LOGGER.debug("Setting the operation mode to: %s", speed)
|
||||
|
||||
await self._try_command(
|
||||
"Setting operation mode of the miio device failed.",
|
||||
self._device.set_mode,
|
||||
OperationMode[speed.title()],
|
||||
AirfreshOperationMode[speed.title()],
|
||||
)
|
||||
|
||||
async def async_set_led_on(self):
|
||||
@ -1097,12 +1087,10 @@ class XiaomiAirFresh(XiaomiGenericDevice):
|
||||
if self._device_features & FEATURE_SET_LED_BRIGHTNESS == 0:
|
||||
return
|
||||
|
||||
from miio.airfresh import LedBrightness
|
||||
|
||||
await self._try_command(
|
||||
"Setting the led brightness of the miio device failed.",
|
||||
self._device.set_led_brightness,
|
||||
LedBrightness(brightness),
|
||||
AirfreshLedBrightness(brightness),
|
||||
)
|
||||
|
||||
async def async_set_extra_features(self, features: int = 1):
|
||||
|
@ -6,13 +6,21 @@ from functools import partial
|
||||
import logging
|
||||
from math import ceil
|
||||
|
||||
from miio import ( # pylint: disable=import-error
|
||||
Ceil,
|
||||
Device,
|
||||
DeviceException,
|
||||
PhilipsBulb,
|
||||
PhilipsEyecare,
|
||||
PhilipsMoonlight,
|
||||
)
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_HS_COLOR,
|
||||
ATTR_COLOR_TEMP,
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_HS_COLOR,
|
||||
DOMAIN,
|
||||
PLATFORM_SCHEMA,
|
||||
SUPPORT_BRIGHTNESS,
|
||||
@ -116,8 +124,6 @@ SERVICE_TO_METHOD = {
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the light from config."""
|
||||
from miio import Device, DeviceException
|
||||
|
||||
if DATA_KEY not in hass.data:
|
||||
hass.data[DATA_KEY] = {}
|
||||
|
||||
@ -147,8 +153,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
raise PlatformNotReady
|
||||
|
||||
if model == "philips.light.sread1":
|
||||
from miio import PhilipsEyecare
|
||||
|
||||
light = PhilipsEyecare(host, token)
|
||||
primary_device = XiaomiPhilipsEyecareLamp(name, light, model, unique_id)
|
||||
devices.append(primary_device)
|
||||
@ -161,15 +165,11 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
# The ambient light doesn't expose additional services.
|
||||
# A hass.data[DATA_KEY] entry isn't needed.
|
||||
elif model in ["philips.light.ceiling", "philips.light.zyceiling"]:
|
||||
from miio import Ceil
|
||||
|
||||
light = Ceil(host, token)
|
||||
device = XiaomiPhilipsCeilingLamp(name, light, model, unique_id)
|
||||
devices.append(device)
|
||||
hass.data[DATA_KEY][host] = device
|
||||
elif model == "philips.light.moonlight":
|
||||
from miio import PhilipsMoonlight
|
||||
|
||||
light = PhilipsMoonlight(host, token)
|
||||
device = XiaomiPhilipsMoonlightLamp(name, light, model, unique_id)
|
||||
devices.append(device)
|
||||
@ -180,15 +180,11 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
"philips.light.candle2",
|
||||
"philips.light.downlight",
|
||||
]:
|
||||
from miio import PhilipsBulb
|
||||
|
||||
light = PhilipsBulb(host, token)
|
||||
device = XiaomiPhilipsBulb(name, light, model, unique_id)
|
||||
devices.append(device)
|
||||
hass.data[DATA_KEY][host] = device
|
||||
elif model == "philips.light.mono1":
|
||||
from miio import PhilipsBulb
|
||||
|
||||
light = PhilipsBulb(host, token)
|
||||
device = XiaomiPhilipsGenericLight(name, light, model, unique_id)
|
||||
devices.append(device)
|
||||
@ -297,8 +293,6 @@ class XiaomiPhilipsAbstractLight(Light):
|
||||
|
||||
async def _try_command(self, mask_error, func, *args, **kwargs):
|
||||
"""Call a light command handling error messages."""
|
||||
from miio import DeviceException
|
||||
|
||||
try:
|
||||
result = await self.hass.async_add_executor_job(
|
||||
partial(func, *args, **kwargs)
|
||||
@ -337,8 +331,6 @@ class XiaomiPhilipsAbstractLight(Light):
|
||||
|
||||
async def async_update(self):
|
||||
"""Fetch state from the device."""
|
||||
from miio import DeviceException
|
||||
|
||||
try:
|
||||
state = await self.hass.async_add_executor_job(self._light.status)
|
||||
except DeviceException as ex:
|
||||
@ -363,8 +355,6 @@ class XiaomiPhilipsGenericLight(XiaomiPhilipsAbstractLight):
|
||||
|
||||
async def async_update(self):
|
||||
"""Fetch state from the device."""
|
||||
from miio import DeviceException
|
||||
|
||||
try:
|
||||
state = await self.hass.async_add_executor_job(self._light.status)
|
||||
except DeviceException as ex:
|
||||
@ -521,8 +511,6 @@ class XiaomiPhilipsBulb(XiaomiPhilipsGenericLight):
|
||||
|
||||
async def async_update(self):
|
||||
"""Fetch state from the device."""
|
||||
from miio import DeviceException
|
||||
|
||||
try:
|
||||
state = await self.hass.async_add_executor_job(self._light.status)
|
||||
except DeviceException as ex:
|
||||
@ -580,8 +568,6 @@ class XiaomiPhilipsCeilingLamp(XiaomiPhilipsBulb):
|
||||
|
||||
async def async_update(self):
|
||||
"""Fetch state from the device."""
|
||||
from miio import DeviceException
|
||||
|
||||
try:
|
||||
state = await self.hass.async_add_executor_job(self._light.status)
|
||||
except DeviceException as ex:
|
||||
@ -626,8 +612,6 @@ class XiaomiPhilipsEyecareLamp(XiaomiPhilipsGenericLight):
|
||||
|
||||
async def async_update(self):
|
||||
"""Fetch state from the device."""
|
||||
from miio import DeviceException
|
||||
|
||||
try:
|
||||
state = await self.hass.async_add_executor_job(self._light.status)
|
||||
except DeviceException as ex:
|
||||
@ -769,8 +753,6 @@ class XiaomiPhilipsEyecareLampAmbientLight(XiaomiPhilipsAbstractLight):
|
||||
|
||||
async def async_update(self):
|
||||
"""Fetch state from the device."""
|
||||
from miio import DeviceException
|
||||
|
||||
try:
|
||||
state = await self.hass.async_add_executor_job(self._light.status)
|
||||
except DeviceException as ex:
|
||||
@ -925,8 +907,6 @@ class XiaomiPhilipsMoonlightLamp(XiaomiPhilipsBulb):
|
||||
|
||||
async def async_update(self):
|
||||
"""Fetch state from the device."""
|
||||
from miio import DeviceException
|
||||
|
||||
try:
|
||||
state = await self.hass.async_add_executor_job(self._light.status)
|
||||
except DeviceException as ex:
|
||||
|
@ -1,28 +1,28 @@
|
||||
"""Support for the Xiaomi IR Remote (Chuangmi IR)."""
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
import time
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from miio import ChuangmiIr, DeviceException # pylint: disable=import-error
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.remote import (
|
||||
PLATFORM_SCHEMA,
|
||||
DOMAIN,
|
||||
ATTR_NUM_REPEATS,
|
||||
ATTR_DELAY_SECS,
|
||||
ATTR_NUM_REPEATS,
|
||||
DEFAULT_DELAY_SECS,
|
||||
DOMAIN,
|
||||
PLATFORM_SCHEMA,
|
||||
RemoteDevice,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_NAME,
|
||||
CONF_HOST,
|
||||
CONF_TOKEN,
|
||||
CONF_TIMEOUT,
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_HIDDEN,
|
||||
CONF_COMMAND,
|
||||
CONF_HOST,
|
||||
CONF_NAME,
|
||||
CONF_TIMEOUT,
|
||||
CONF_TOKEN,
|
||||
)
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
@ -73,8 +73,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the Xiaomi IR Remote (Chuangmi IR) platform."""
|
||||
from miio import ChuangmiIr, DeviceException
|
||||
|
||||
host = config[CONF_HOST]
|
||||
token = config[CONF_TOKEN]
|
||||
|
||||
@ -226,8 +224,6 @@ class XiaomiMiioRemote(RemoteDevice):
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return False if device is unreachable, else True."""
|
||||
from miio import DeviceException
|
||||
|
||||
try:
|
||||
self.device.info()
|
||||
return True
|
||||
@ -262,8 +258,6 @@ class XiaomiMiioRemote(RemoteDevice):
|
||||
|
||||
def _send_command(self, payload):
|
||||
"""Send a command."""
|
||||
from miio import DeviceException
|
||||
|
||||
_LOGGER.debug("Sending payload: '%s'", payload)
|
||||
try:
|
||||
self.device.play(payload)
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""Support for Xiaomi Mi Air Quality Monitor (PM2.5)."""
|
||||
import logging
|
||||
|
||||
from miio import AirQualityMonitor, DeviceException # pylint: disable=import-error
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
@ -37,8 +38,6 @@ SUCCESS = ["ok"]
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the sensor from config."""
|
||||
from miio import AirQualityMonitor, DeviceException
|
||||
|
||||
if DATA_KEY not in hass.data:
|
||||
hass.data[DATA_KEY] = {}
|
||||
|
||||
@ -135,8 +134,6 @@ class XiaomiAirQualityMonitor(Entity):
|
||||
|
||||
async def async_update(self):
|
||||
"""Fetch state from the miio device."""
|
||||
from miio import DeviceException
|
||||
|
||||
try:
|
||||
state = await self.hass.async_add_executor_job(self._device.status)
|
||||
_LOGGER.debug("Got new state: %s", state)
|
||||
|
@ -3,6 +3,14 @@ import asyncio
|
||||
from functools import partial
|
||||
import logging
|
||||
|
||||
from miio import ( # pylint: disable=import-error
|
||||
AirConditioningCompanionV3,
|
||||
ChuangmiPlug,
|
||||
Device,
|
||||
DeviceException,
|
||||
PowerStrip,
|
||||
)
|
||||
from miio.powerstrip import PowerMode # pylint: disable=import-error
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.switch import DOMAIN, PLATFORM_SCHEMA, SwitchDevice
|
||||
@ -102,8 +110,6 @@ SERVICE_TO_METHOD = {
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the switch from config."""
|
||||
from miio import Device, DeviceException
|
||||
|
||||
if DATA_KEY not in hass.data:
|
||||
hass.data[DATA_KEY] = {}
|
||||
|
||||
@ -133,8 +139,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
raise PlatformNotReady
|
||||
|
||||
if model in ["chuangmi.plug.v1", "chuangmi.plug.v3"]:
|
||||
from miio import ChuangmiPlug
|
||||
|
||||
plug = ChuangmiPlug(host, token, model=model)
|
||||
|
||||
# The device has two switchable channels (mains and a USB port).
|
||||
@ -145,8 +149,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
hass.data[DATA_KEY][host] = device
|
||||
|
||||
elif model in ["qmi.powerstrip.v1", "zimi.powerstrip.v2"]:
|
||||
from miio import PowerStrip
|
||||
|
||||
plug = PowerStrip(host, token, model=model)
|
||||
device = XiaomiPowerStripSwitch(name, plug, model, unique_id)
|
||||
devices.append(device)
|
||||
@ -157,15 +159,11 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
"chuangmi.plug.v2",
|
||||
"chuangmi.plug.hmi205",
|
||||
]:
|
||||
from miio import ChuangmiPlug
|
||||
|
||||
plug = ChuangmiPlug(host, token, model=model)
|
||||
device = XiaomiPlugGenericSwitch(name, plug, model, unique_id)
|
||||
devices.append(device)
|
||||
hass.data[DATA_KEY][host] = device
|
||||
elif model in ["lumi.acpartner.v3"]:
|
||||
from miio import AirConditioningCompanionV3
|
||||
|
||||
plug = AirConditioningCompanionV3(host, token)
|
||||
device = XiaomiAirConditioningCompanionSwitch(name, plug, model, unique_id)
|
||||
devices.append(device)
|
||||
@ -268,8 +266,6 @@ class XiaomiPlugGenericSwitch(SwitchDevice):
|
||||
|
||||
async def _try_command(self, mask_error, func, *args, **kwargs):
|
||||
"""Call a plug command handling error messages."""
|
||||
from miio import DeviceException
|
||||
|
||||
try:
|
||||
result = await self.hass.async_add_executor_job(
|
||||
partial(func, *args, **kwargs)
|
||||
@ -305,8 +301,6 @@ class XiaomiPlugGenericSwitch(SwitchDevice):
|
||||
|
||||
async def async_update(self):
|
||||
"""Fetch state from the device."""
|
||||
from miio import DeviceException
|
||||
|
||||
# On state change the device doesn't provide the new state immediately.
|
||||
if self._skip_update:
|
||||
self._skip_update = False
|
||||
@ -379,8 +373,6 @@ class XiaomiPowerStripSwitch(XiaomiPlugGenericSwitch):
|
||||
|
||||
async def async_update(self):
|
||||
"""Fetch state from the device."""
|
||||
from miio import DeviceException
|
||||
|
||||
# On state change the device doesn't provide the new state immediately.
|
||||
if self._skip_update:
|
||||
self._skip_update = False
|
||||
@ -417,8 +409,6 @@ class XiaomiPowerStripSwitch(XiaomiPlugGenericSwitch):
|
||||
if self._device_features & FEATURE_SET_POWER_MODE == 0:
|
||||
return
|
||||
|
||||
from miio.powerstrip import PowerMode
|
||||
|
||||
await self._try_command(
|
||||
"Setting the power mode of the power strip failed.",
|
||||
self._plug.set_power_mode,
|
||||
@ -477,8 +467,6 @@ class ChuangMiPlugSwitch(XiaomiPlugGenericSwitch):
|
||||
|
||||
async def async_update(self):
|
||||
"""Fetch state from the device."""
|
||||
from miio import DeviceException
|
||||
|
||||
# On state change the device doesn't provide the new state immediately.
|
||||
if self._skip_update:
|
||||
self._skip_update = False
|
||||
@ -538,8 +526,6 @@ class XiaomiAirConditioningCompanionSwitch(XiaomiPlugGenericSwitch):
|
||||
|
||||
async def async_update(self):
|
||||
"""Fetch state from the device."""
|
||||
from miio import DeviceException
|
||||
|
||||
# On state change the device doesn't provide the new state immediately.
|
||||
if self._skip_update:
|
||||
self._skip_update = False
|
||||
|
@ -3,12 +3,19 @@ import asyncio
|
||||
from functools import partial
|
||||
import logging
|
||||
|
||||
from miio import DeviceException, Vacuum # pylint: disable=import-error
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.vacuum import (
|
||||
ATTR_CLEANED_AREA,
|
||||
DOMAIN,
|
||||
PLATFORM_SCHEMA,
|
||||
STATE_CLEANING,
|
||||
STATE_DOCKED,
|
||||
STATE_ERROR,
|
||||
STATE_IDLE,
|
||||
STATE_PAUSED,
|
||||
STATE_RETURNING,
|
||||
SUPPORT_BATTERY,
|
||||
SUPPORT_CLEAN_SPOT,
|
||||
SUPPORT_FAN_SPEED,
|
||||
@ -16,16 +23,10 @@ from homeassistant.components.vacuum import (
|
||||
SUPPORT_PAUSE,
|
||||
SUPPORT_RETURN_HOME,
|
||||
SUPPORT_SEND_COMMAND,
|
||||
SUPPORT_STOP,
|
||||
SUPPORT_STATE,
|
||||
SUPPORT_START,
|
||||
SUPPORT_STATE,
|
||||
SUPPORT_STOP,
|
||||
StateVacuumDevice,
|
||||
STATE_CLEANING,
|
||||
STATE_DOCKED,
|
||||
STATE_PAUSED,
|
||||
STATE_IDLE,
|
||||
STATE_RETURNING,
|
||||
STATE_ERROR,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
@ -177,8 +178,6 @@ STATE_CODE_TO_STATE = {
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the Xiaomi vacuum cleaner robot platform."""
|
||||
from miio import Vacuum
|
||||
|
||||
if DATA_KEY not in hass.data:
|
||||
hass.data[DATA_KEY] = {}
|
||||
|
||||
@ -348,8 +347,6 @@ class MiroboVacuum(StateVacuumDevice):
|
||||
|
||||
async def _try_command(self, mask_error, func, *args, **kwargs):
|
||||
"""Call a vacuum command handling error messages."""
|
||||
from miio import DeviceException
|
||||
|
||||
try:
|
||||
await self.hass.async_add_executor_job(partial(func, *args, **kwargs))
|
||||
return True
|
||||
@ -450,8 +447,6 @@ class MiroboVacuum(StateVacuumDevice):
|
||||
|
||||
def update(self):
|
||||
"""Fetch state from the device."""
|
||||
from miio import DeviceException
|
||||
|
||||
try:
|
||||
state = self._vacuum.status()
|
||||
self.vacuum_state = state
|
||||
@ -469,8 +464,6 @@ class MiroboVacuum(StateVacuumDevice):
|
||||
|
||||
async def async_clean_zone(self, zone, repeats=1):
|
||||
"""Clean selected area for the number of repeats indicated."""
|
||||
from miio import DeviceException
|
||||
|
||||
for _zone in zone:
|
||||
_zone.append(repeats)
|
||||
_LOGGER.debug("Zone with repeats: %s", zone)
|
||||
|
Loading…
Reference in New Issue
Block a user