1 """Support for Xiaomi Smart WiFi Socket and Smart Power Strip."""
3 from __future__
import annotations
6 from dataclasses
import dataclass
7 from functools
import partial
11 from miio
import AirConditioningCompanionV3, ChuangmiPlug, DeviceException, PowerStrip
12 from miio.powerstrip
import PowerMode
13 import voluptuous
as vol
18 SwitchEntityDescription,
39 FEATURE_FLAGS_AIRFRESH,
40 FEATURE_FLAGS_AIRFRESH_A1,
41 FEATURE_FLAGS_AIRFRESH_T2017,
42 FEATURE_FLAGS_AIRFRESH_VA4,
43 FEATURE_FLAGS_AIRHUMIDIFIER,
44 FEATURE_FLAGS_AIRHUMIDIFIER_CA4,
45 FEATURE_FLAGS_AIRHUMIDIFIER_CA_AND_CB,
46 FEATURE_FLAGS_AIRHUMIDIFIER_MJSSQ,
47 FEATURE_FLAGS_AIRPURIFIER_2S,
48 FEATURE_FLAGS_AIRPURIFIER_3C,
49 FEATURE_FLAGS_AIRPURIFIER_4,
50 FEATURE_FLAGS_AIRPURIFIER_4_LITE,
51 FEATURE_FLAGS_AIRPURIFIER_MIIO,
52 FEATURE_FLAGS_AIRPURIFIER_MIOT,
53 FEATURE_FLAGS_AIRPURIFIER_PRO,
54 FEATURE_FLAGS_AIRPURIFIER_PRO_V7,
55 FEATURE_FLAGS_AIRPURIFIER_V1,
56 FEATURE_FLAGS_AIRPURIFIER_V3,
57 FEATURE_FLAGS_AIRPURIFIER_ZA1,
62 FEATURE_FLAGS_FAN_P10_P11_P18,
63 FEATURE_FLAGS_FAN_ZA5,
65 FEATURE_SET_AUTO_DETECT,
67 FEATURE_SET_CHILD_LOCK,
72 FEATURE_SET_LEARN_MODE,
81 MODEL_AIRHUMIDIFIER_CA1,
82 MODEL_AIRHUMIDIFIER_CA4,
83 MODEL_AIRHUMIDIFIER_CB1,
87 MODEL_AIRPURIFIER_3C_REV_A,
89 MODEL_AIRPURIFIER_4_LITE_RMA1,
90 MODEL_AIRPURIFIER_4_LITE_RMB1,
91 MODEL_AIRPURIFIER_4_PRO,
92 MODEL_AIRPURIFIER_PRO,
93 MODEL_AIRPURIFIER_PRO_V7,
96 MODEL_AIRPURIFIER_ZA1,
109 MODELS_HUMIDIFIER_MJJSQ,
110 MODELS_PURIFIER_MIIO,
111 MODELS_PURIFIER_MIOT,
112 SERVICE_SET_POWER_MODE,
113 SERVICE_SET_POWER_PRICE,
114 SERVICE_SET_WIFI_LED_OFF,
115 SERVICE_SET_WIFI_LED_ON,
118 from .entity
import XiaomiCoordinatedMiioEntity, XiaomiGatewayDevice, XiaomiMiioEntity
119 from .typing
import ServiceMethodDetails
121 _LOGGER = logging.getLogger(__name__)
123 DEFAULT_NAME =
"Xiaomi Miio Switch"
124 DATA_KEY =
"switch.xiaomi_miio"
126 MODEL_POWER_STRIP_V2 =
"zimi.powerstrip.v2"
127 MODEL_PLUG_V3 =
"chuangmi.plug.v3"
129 KEY_CHANNEL =
"channel"
130 GATEWAY_SWITCH_VARS = {
131 "status_ch0": {KEY_CHANNEL: 0},
132 "status_ch1": {KEY_CHANNEL: 1},
133 "status_ch2": {KEY_CHANNEL: 2},
137 ATTR_AUTO_DETECT =
"auto_detect"
138 ATTR_BUZZER =
"buzzer"
139 ATTR_CHILD_LOCK =
"child_lock"
140 ATTR_CLEAN =
"clean_mode"
141 ATTR_DISPLAY =
"display"
143 ATTR_LEARN_MODE =
"learn_mode"
145 ATTR_IONIZER =
"ionizer"
147 ATTR_LOAD_POWER =
"load_power"
150 ATTR_POWER_MODE =
"power_mode"
151 ATTR_POWER_PRICE =
"power_price"
154 ATTR_WIFI_LED =
"wifi_led"
156 FEATURE_SET_POWER_MODE = 1
157 FEATURE_SET_WIFI_LED = 2
158 FEATURE_SET_POWER_PRICE = 4
160 FEATURE_FLAGS_GENERIC = 0
162 FEATURE_FLAGS_POWER_STRIP_V1 = (
163 FEATURE_SET_POWER_MODE | FEATURE_SET_WIFI_LED | FEATURE_SET_POWER_PRICE
166 FEATURE_FLAGS_POWER_STRIP_V2 = FEATURE_SET_WIFI_LED | FEATURE_SET_POWER_PRICE
168 FEATURE_FLAGS_PLUG_V3 = FEATURE_SET_WIFI_LED
170 SERVICE_SCHEMA = vol.Schema({vol.Optional(ATTR_ENTITY_ID): cv.entity_ids})
172 SERVICE_SCHEMA_POWER_MODE = SERVICE_SCHEMA.extend(
173 {vol.Required(ATTR_MODE): vol.All(vol.In([
"green",
"normal"]))}
176 SERVICE_SCHEMA_POWER_PRICE = SERVICE_SCHEMA.extend(
177 {vol.Required(ATTR_PRICE): cv.positive_float}
180 SERVICE_TO_METHOD = {
184 method=
"async_set_power_mode",
185 schema=SERVICE_SCHEMA_POWER_MODE,
188 method=
"async_set_power_price",
189 schema=SERVICE_SCHEMA_POWER_PRICE,
193 MODEL_TO_FEATURES_MAP = {
194 MODEL_AIRFRESH_A1: FEATURE_FLAGS_AIRFRESH_A1,
195 MODEL_AIRFRESH_VA2: FEATURE_FLAGS_AIRFRESH,
196 MODEL_AIRFRESH_VA4: FEATURE_FLAGS_AIRFRESH_VA4,
197 MODEL_AIRFRESH_T2017: FEATURE_FLAGS_AIRFRESH_T2017,
198 MODEL_AIRHUMIDIFIER_CA1: FEATURE_FLAGS_AIRHUMIDIFIER_CA_AND_CB,
199 MODEL_AIRHUMIDIFIER_CA4: FEATURE_FLAGS_AIRHUMIDIFIER_CA4,
200 MODEL_AIRHUMIDIFIER_CB1: FEATURE_FLAGS_AIRHUMIDIFIER_CA_AND_CB,
201 MODEL_AIRPURIFIER_2H: FEATURE_FLAGS_AIRPURIFIER_2S,
202 MODEL_AIRPURIFIER_2S: FEATURE_FLAGS_AIRPURIFIER_2S,
203 MODEL_AIRPURIFIER_3C: FEATURE_FLAGS_AIRPURIFIER_3C,
204 MODEL_AIRPURIFIER_3C_REV_A: FEATURE_FLAGS_AIRPURIFIER_3C,
205 MODEL_AIRPURIFIER_PRO: FEATURE_FLAGS_AIRPURIFIER_PRO,
206 MODEL_AIRPURIFIER_PRO_V7: FEATURE_FLAGS_AIRPURIFIER_PRO_V7,
207 MODEL_AIRPURIFIER_V1: FEATURE_FLAGS_AIRPURIFIER_V1,
208 MODEL_AIRPURIFIER_V3: FEATURE_FLAGS_AIRPURIFIER_V3,
209 MODEL_AIRPURIFIER_4_LITE_RMA1: FEATURE_FLAGS_AIRPURIFIER_4_LITE,
210 MODEL_AIRPURIFIER_4_LITE_RMB1: FEATURE_FLAGS_AIRPURIFIER_4_LITE,
211 MODEL_AIRPURIFIER_4: FEATURE_FLAGS_AIRPURIFIER_4,
212 MODEL_AIRPURIFIER_4_PRO: FEATURE_FLAGS_AIRPURIFIER_4,
213 MODEL_AIRPURIFIER_ZA1: FEATURE_FLAGS_AIRPURIFIER_ZA1,
214 MODEL_FAN_1C: FEATURE_FLAGS_FAN_1C,
215 MODEL_FAN_P10: FEATURE_FLAGS_FAN_P10_P11_P18,
216 MODEL_FAN_P11: FEATURE_FLAGS_FAN_P10_P11_P18,
217 MODEL_FAN_P18: FEATURE_FLAGS_FAN_P10_P11_P18,
218 MODEL_FAN_P5: FEATURE_FLAGS_FAN_P5,
219 MODEL_FAN_P9: FEATURE_FLAGS_FAN_P9,
220 MODEL_FAN_ZA1: FEATURE_FLAGS_FAN,
221 MODEL_FAN_ZA3: FEATURE_FLAGS_FAN,
222 MODEL_FAN_ZA4: FEATURE_FLAGS_FAN,
223 MODEL_FAN_ZA5: FEATURE_FLAGS_FAN_ZA5,
227 @dataclass(frozen=True, kw_only=True)
229 """A class that describes switch entities."""
235 available_with_device_off: bool =
True
241 feature=FEATURE_SET_BUZZER,
242 translation_key=ATTR_BUZZER,
243 icon=
"mdi:volume-high",
244 method_on=
"async_set_buzzer_on",
245 method_off=
"async_set_buzzer_off",
246 entity_category=EntityCategory.CONFIG,
250 feature=FEATURE_SET_CHILD_LOCK,
251 translation_key=ATTR_CHILD_LOCK,
253 method_on=
"async_set_child_lock_on",
254 method_off=
"async_set_child_lock_off",
255 entity_category=EntityCategory.CONFIG,
259 feature=FEATURE_SET_DISPLAY,
260 translation_key=ATTR_DISPLAY,
261 icon=
"mdi:led-outline",
262 method_on=
"async_set_display_on",
263 method_off=
"async_set_display_off",
264 entity_category=EntityCategory.CONFIG,
268 feature=FEATURE_SET_DRY,
269 translation_key=ATTR_DRY,
270 icon=
"mdi:hair-dryer",
271 method_on=
"async_set_dry_on",
272 method_off=
"async_set_dry_off",
273 entity_category=EntityCategory.CONFIG,
277 feature=FEATURE_SET_CLEAN,
278 translation_key=ATTR_CLEAN,
280 method_on=
"async_set_clean_on",
281 method_off=
"async_set_clean_off",
282 available_with_device_off=
False,
283 entity_category=EntityCategory.CONFIG,
287 feature=FEATURE_SET_LED,
288 translation_key=ATTR_LED,
289 icon=
"mdi:led-outline",
290 method_on=
"async_set_led_on",
291 method_off=
"async_set_led_off",
292 entity_category=EntityCategory.CONFIG,
296 feature=FEATURE_SET_LEARN_MODE,
297 translation_key=ATTR_LEARN_MODE,
298 icon=
"mdi:school-outline",
299 method_on=
"async_set_learn_mode_on",
300 method_off=
"async_set_learn_mode_off",
301 entity_category=EntityCategory.CONFIG,
304 key=ATTR_AUTO_DETECT,
305 feature=FEATURE_SET_AUTO_DETECT,
306 translation_key=ATTR_AUTO_DETECT,
307 method_on=
"async_set_auto_detect_on",
308 method_off=
"async_set_auto_detect_off",
309 entity_category=EntityCategory.CONFIG,
313 feature=FEATURE_SET_IONIZER,
314 translation_key=ATTR_IONIZER,
316 method_on=
"async_set_ionizer_on",
317 method_off=
"async_set_ionizer_off",
318 entity_category=EntityCategory.CONFIG,
322 feature=FEATURE_SET_ANION,
323 translation_key=ATTR_ANION,
325 method_on=
"async_set_anion_on",
326 method_off=
"async_set_anion_off",
327 entity_category=EntityCategory.CONFIG,
331 feature=FEATURE_SET_PTC,
332 translation_key=ATTR_PTC,
334 method_on=
"async_set_ptc_on",
335 method_off=
"async_set_ptc_off",
336 entity_category=EntityCategory.CONFIG,
343 config_entry: ConfigEntry,
344 async_add_entities: AddEntitiesCallback,
346 """Set up the switch from a config entry."""
347 model = config_entry.data[CONF_MODEL]
348 if model
in (*MODELS_HUMIDIFIER, *MODELS_FAN):
355 """Set up the coordinated switch from a config entry."""
356 model = config_entry.data[CONF_MODEL]
357 unique_id = config_entry.unique_id
358 device = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE]
359 coordinator = hass.data[DOMAIN][config_entry.entry_id][KEY_COORDINATOR]
361 if DATA_KEY
not in hass.data:
362 hass.data[DATA_KEY] = {}
366 if model
in MODEL_TO_FEATURES_MAP:
367 device_features = MODEL_TO_FEATURES_MAP[model]
368 elif model
in MODELS_HUMIDIFIER_MJJSQ:
369 device_features = FEATURE_FLAGS_AIRHUMIDIFIER_MJSSQ
370 elif model
in MODELS_HUMIDIFIER:
371 device_features = FEATURE_FLAGS_AIRHUMIDIFIER
372 elif model
in MODELS_PURIFIER_MIIO:
373 device_features = FEATURE_FLAGS_AIRPURIFIER_MIIO
374 elif model
in MODELS_PURIFIER_MIOT:
375 device_features = FEATURE_FLAGS_AIRPURIFIER_MIOT
381 f
"{description.key}_{unique_id}",
385 for description
in SWITCH_TYPES
386 if description.feature & device_features
391 """Set up the other type switch from a config entry."""
393 host = config_entry.data[CONF_HOST]
394 token = config_entry.data[CONF_TOKEN]
395 name = config_entry.title
396 model = config_entry.data[CONF_MODEL]
397 unique_id = config_entry.unique_id
398 if config_entry.data[CONF_FLOW_TYPE] == CONF_GATEWAY:
399 gateway = hass.data[DOMAIN][config_entry.entry_id][CONF_GATEWAY]
401 sub_devices = gateway.devices
402 for sub_device
in sub_devices.values():
403 if sub_device.device_type !=
"Switch":
405 coordinator = hass.data[DOMAIN][config_entry.entry_id][KEY_COORDINATOR][
408 switch_variables = set(sub_device.status) & set(GATEWAY_SWITCH_VARS)
413 coordinator, sub_device, config_entry, variable
415 for variable
in switch_variables
419 if config_entry.data[CONF_FLOW_TYPE] == CONF_DEVICE
or (
420 config_entry.data[CONF_FLOW_TYPE] == CONF_GATEWAY
421 and model ==
"lumi.acpartner.v3"
423 if DATA_KEY
not in hass.data:
424 hass.data[DATA_KEY] = {}
426 _LOGGER.debug(
"Initializing with host %s (token %s...)", host, token[:5])
428 if model
in [
"chuangmi.plug.v1",
"chuangmi.plug.v3",
"chuangmi.plug.hmi208"]:
429 plug = ChuangmiPlug(host, token, model=model)
433 for channel_usb
in (
True,
False):
435 unique_id_ch = f
"{unique_id}-USB"
437 unique_id_ch = f
"{unique_id}-mains"
439 name, plug, config_entry, unique_id_ch, channel_usb
441 entities.append(device)
442 hass.data[DATA_KEY][host] = device
443 elif model
in [
"qmi.powerstrip.v1",
"zimi.powerstrip.v2"]:
444 plug = PowerStrip(host, token, model=model)
446 entities.append(device)
447 hass.data[DATA_KEY][host] = device
452 "chuangmi.plug.hmi205",
453 "chuangmi.plug.hmi206",
455 plug = ChuangmiPlug(host, token, model=model)
457 entities.append(device)
458 hass.data[DATA_KEY][host] = device
459 elif model
in [
"lumi.acpartner.v3"]:
460 plug = AirConditioningCompanionV3(host, token)
462 name, plug, config_entry, unique_id
464 entities.append(device)
465 hass.data[DATA_KEY][host] = device
469 "Unsupported device found! Please create an issue at "
470 "https://github.com/rytilahti/python-miio/issues "
471 "and provide the following data: %s"
476 async
def async_service_handler(service: ServiceCall) ->
None:
477 """Map services to methods on XiaomiPlugGenericSwitch."""
478 method = SERVICE_TO_METHOD[service.service]
481 for key, value
in service.data.items()
482 if key != ATTR_ENTITY_ID
484 if entity_ids := service.data.get(ATTR_ENTITY_ID):
487 for device
in hass.data[DATA_KEY].values()
488 if device.entity_id
in entity_ids
491 devices = hass.data[DATA_KEY].values()
494 for device
in devices:
495 if not hasattr(device, method.method):
497 await getattr(device, method.method)(**params)
499 asyncio.create_task(device.async_update_ha_state(
True))
503 await asyncio.wait(update_tasks)
505 for plug_service, method
in SERVICE_TO_METHOD.items():
506 schema = method.schema
or SERVICE_SCHEMA
507 hass.services.async_register(
508 DOMAIN, plug_service, async_service_handler, schema=schema
515 """Representation of a Xiaomi Plug Generic."""
517 entity_description: XiaomiMiioSwitchDescription
519 def __init__(self, device, entry, unique_id, coordinator, description):
520 """Initialize the plug switch."""
521 super().
__init__(device, entry, unique_id, coordinator)
524 self.coordinator.data, description.key
530 """Fetch state from the device."""
532 self.
_attr_is_on_attr_is_on = self._extract_value_from_attribute(
539 """Return true when state is known."""
542 and not self.coordinator.data.is_on
546 return super().available
549 """Turn on an option of the miio device."""
557 """Turn off an option of the miio device."""
565 """Turn the buzzer on."""
566 return await self._try_command(
567 "Turning the buzzer of the miio device on failed.",
568 self._device.set_buzzer,
573 """Turn the buzzer off."""
574 return await self._try_command(
575 "Turning the buzzer of the miio device off failed.",
576 self._device.set_buzzer,
581 """Turn the child lock on."""
582 return await self._try_command(
583 "Turning the child lock of the miio device on failed.",
584 self._device.set_child_lock,
589 """Turn the child lock off."""
590 return await self._try_command(
591 "Turning the child lock of the miio device off failed.",
592 self._device.set_child_lock,
597 """Turn the display on."""
598 return await self._try_command(
599 "Turning the display of the miio device on failed.",
600 self._device.set_display,
605 """Turn the display off."""
606 return await self._try_command(
607 "Turning the display of the miio device off failed.",
608 self._device.set_display,
613 """Turn the dry mode on."""
614 return await self._try_command(
615 "Turning the dry mode of the miio device on failed.",
616 self._device.set_dry,
621 """Turn the dry mode off."""
622 return await self._try_command(
623 "Turning the dry mode of the miio device off failed.",
624 self._device.set_dry,
629 """Turn the dry mode on."""
630 return await self._try_command(
631 "Turning the clean mode of the miio device on failed.",
632 self._device.set_clean_mode,
637 """Turn the dry mode off."""
638 return await self._try_command(
639 "Turning the clean mode of the miio device off failed.",
640 self._device.set_clean_mode,
645 """Turn the led on."""
646 return await self._try_command(
647 "Turning the led of the miio device on failed.",
648 self._device.set_led,
653 """Turn the led off."""
654 return await self._try_command(
655 "Turning the led of the miio device off failed.",
656 self._device.set_led,
661 """Turn the learn mode on."""
662 return await self._try_command(
663 "Turning the learn mode of the miio device on failed.",
664 self._device.set_learn_mode,
669 """Turn the learn mode off."""
670 return await self._try_command(
671 "Turning the learn mode of the miio device off failed.",
672 self._device.set_learn_mode,
677 """Turn auto detect on."""
678 return await self._try_command(
679 "Turning auto detect of the miio device on failed.",
680 self._device.set_auto_detect,
685 """Turn auto detect off."""
686 return await self._try_command(
687 "Turning auto detect of the miio device off failed.",
688 self._device.set_auto_detect,
693 """Turn ionizer on."""
694 return await self._try_command(
695 "Turning ionizer of the miio device on failed.",
696 self._device.set_ionizer,
701 """Turn ionizer off."""
702 return await self._try_command(
703 "Turning ionizer of the miio device off failed.",
704 self._device.set_ionizer,
709 """Turn ionizer on."""
710 return await self._try_command(
711 "Turning ionizer of the miio device on failed.",
712 self._device.set_anion,
717 """Turn ionizer off."""
718 return await self._try_command(
719 "Turning ionizer of the miio device off failed.",
720 self._device.set_anion,
725 """Turn ionizer on."""
726 return await self._try_command(
727 "Turning ionizer of the miio device on failed.",
728 self._device.set_ptc,
733 """Turn ionizer off."""
734 return await self._try_command(
735 "Turning ionizer of the miio device off failed.",
736 self._device.set_ptc,
742 """Representation of a XiaomiGatewaySwitch."""
744 _attr_device_class = SwitchDeviceClass.SWITCH
746 def __init__(self, coordinator, sub_device, entry, variable):
747 """Initialize the XiaomiSensor."""
748 super().
__init__(coordinator, sub_device, entry)
749 self.
_channel_channel = GATEWAY_SWITCH_VARS[variable][KEY_CHANNEL]
752 self.
_name_name_name = f
"{sub_device.name} ch{self._channel} ({sub_device.sid})"
756 """Return true if switch is on."""
760 """Turn the switch on."""
764 """Turn the switch off."""
768 """Toggle the switch."""
773 """Representation of a Xiaomi Plug Generic."""
775 def __init__(self, name, device, entry, unique_id):
776 """Initialize the plug switch."""
777 super().
__init__(name, device, entry, unique_id)
779 self.
_icon_icon =
"mdi:power-socket"
788 """Return the icon to use for device if any."""
789 return self.
_icon_icon
793 """Return true when state is known."""
798 """Return the state attributes of the device."""
803 """Return true if switch is on."""
807 """Call a plug command handling error messages."""
809 result = await self.
hasshass.async_add_executor_job(
810 partial(func, *args, **kwargs)
812 except DeviceException
as exc:
814 _LOGGER.error(mask_error, exc)
819 _LOGGER.debug(
"Response received from plug: %s", result)
822 if func
in [
"usb_on",
"usb_off"]
and result == 0:
825 return result == SUCCESS
828 """Turn the plug on."""
829 result = await self.
_try_command_try_command(
"Turning the plug on failed", self.
_device_device.on)
836 """Turn the plug off."""
838 "Turning the plug off failed", self.
_device_device.off
846 """Fetch state from the device."""
853 state = await self.
hasshass.async_add_executor_job(self.
_device_device.status)
854 _LOGGER.debug(
"Got new state: %s", state)
857 self.
_state_state = state.is_on
858 self.
_state_attrs_state_attrs[ATTR_TEMPERATURE] = state.temperature
860 except DeviceException
as ex:
863 _LOGGER.error(
"Got exception while fetching the state: %s", ex)
866 """Turn the wifi led on."""
871 "Turning the wifi led on failed", self.
_device_device.set_wifi_led,
True
875 """Turn the wifi led on."""
880 "Turning the wifi led off failed", self.
_device_device.set_wifi_led,
False
884 """Set the power price."""
889 "Setting the power price of the power strip failed",
890 self.
_device_device.set_power_price,
896 """Representation of a Xiaomi Power Strip."""
899 """Initialize the plug switch."""
900 super().
__init__(name, plug, model, unique_id)
919 """Fetch state from the device."""
926 state = await self.
hasshass.async_add_executor_job(self.
_device_device.status)
927 _LOGGER.debug(
"Got new state: %s", state)
932 {ATTR_TEMPERATURE: state.temperature, ATTR_LOAD_POWER: state.load_power}
936 self.
_state_attrs_state_attrs[ATTR_POWER_MODE] = state.mode.value
939 self.
_state_attrs_state_attrs[ATTR_WIFI_LED] = state.wifi_led
943 and state.power_price
945 self.
_state_attrs_state_attrs[ATTR_POWER_PRICE] = state.power_price
947 except DeviceException
as ex:
950 _LOGGER.error(
"Got exception while fetching the state: %s", ex)
953 """Set the power mode."""
958 "Setting the power mode of the power strip failed",
959 self.
_device_device.set_power_mode,
965 """Representation of a Chuang Mi Plug V1 and V3."""
967 def __init__(self, name, plug, entry, unique_id, channel_usb):
968 """Initialize the plug switch."""
969 name = f
"{name} USB" if channel_usb
else name
971 if unique_id
is not None and channel_usb:
972 unique_id = f
"{unique_id}-usb"
974 super().
__init__(name, plug, entry, unique_id)
984 """Turn a channel on."""
987 "Turning the plug on failed", self.
_device_device.usb_on
991 "Turning the plug on failed", self.
_device_device.on
999 """Turn a channel off."""
1002 "Turning the plug off failed", self.
_device_device.usb_off
1006 "Turning the plug off failed", self.
_device_device.off
1014 """Fetch state from the device."""
1021 state = await self.
hasshass.async_add_executor_job(self.
_device_device.status)
1022 _LOGGER.debug(
"Got new state: %s", state)
1030 self.
_state_attrs_state_attrs[ATTR_TEMPERATURE] = state.temperature
1033 self.
_state_attrs_state_attrs[ATTR_WIFI_LED] = state.wifi_led
1035 if self.
_channel_usb_channel_usb
is False and state.load_power:
1036 self.
_state_attrs_state_attrs[ATTR_LOAD_POWER] = state.load_power
1038 except DeviceException
as ex:
1041 _LOGGER.error(
"Got exception while fetching the state: %s", ex)
1045 """Representation of a Xiaomi AirConditioning Companion."""
1048 """Initialize the acpartner switch."""
1049 super().
__init__(name, plug, model, unique_id)
1051 self.
_state_attrs_state_attrs.
update({ATTR_TEMPERATURE:
None, ATTR_LOAD_POWER:
None})
1054 """Turn the socket on."""
1056 "Turning the socket on failed", self.
_device_device.socket_on
1064 """Turn the socket off."""
1066 "Turning the socket off failed", self.
_device_device.socket_off
1074 """Fetch state from the device."""
1081 state = await self.
hasshass.async_add_executor_job(self.
_device_device.status)
1082 _LOGGER.debug(
"Got new state: %s", state)
1086 self.
_state_attrs_state_attrs[ATTR_LOAD_POWER] = state.load_power
1088 except DeviceException
as ex:
1091 _LOGGER.error(
"Got exception while fetching the state: %s", ex)
None async_turn_off(self, **Any kwargs)
def __init__(self, name, plug, entry, unique_id, channel_usb)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
def __init__(self, name, plug, model, unique_id)
None async_turn_on(self, **Any kwargs)
def __init__(self, coordinator, sub_device, entry, variable)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None async_toggle(self, **Any kwargs)
bool async_set_clean_off(self)
bool async_set_anion_on(self)
bool async_set_ionizer_off(self)
None async_turn_on(self, **Any kwargs)
bool async_set_dry_off(self)
bool async_set_learn_mode_on(self)
bool async_set_auto_detect_on(self)
bool async_set_child_lock_off(self)
bool async_set_ionizer_on(self)
bool async_set_ptc_on(self)
def __init__(self, device, entry, unique_id, coordinator, description)
bool async_set_ptc_off(self)
None async_turn_off(self, **Any kwargs)
bool async_set_buzzer_on(self)
bool async_set_display_on(self)
bool async_set_led_on(self)
bool async_set_led_off(self)
def _handle_coordinator_update(self)
bool async_set_dry_on(self)
bool async_set_buzzer_off(self)
bool async_set_display_off(self)
bool async_set_auto_detect_off(self)
bool async_set_clean_on(self)
bool async_set_learn_mode_off(self)
bool async_set_anion_off(self)
bool async_set_child_lock_on(self)
def async_set_wifi_led_off(self)
def __init__(self, name, device, entry, unique_id)
None async_turn_on(self, **Any kwargs)
def async_set_power_price(self, int price)
None async_turn_off(self, **Any kwargs)
def _try_command(self, mask_error, func, *args, **kwargs)
def extra_state_attributes(self)
def async_set_wifi_led_on(self)
def async_set_power_mode(self, str mode)
def __init__(self, name, plug, model, unique_id)
None async_write_ha_state(self)
IssData update(pyiss.ISS iss)
def async_setup_coordinated_entry(hass, config_entry, async_add_entities)
def async_setup_other_entry(hass, config_entry, async_add_entities)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)