1 """Support for Xiaomi Aqara binary sensors."""
11 from .const
import DOMAIN, GATEWAYS_KEY
12 from .entity
import XiaomiDevice
14 _LOGGER = logging.getLogger(__name__)
17 ATTR_LOAD_POWER =
"load_power"
20 ATTR_POWER_CONSUMED =
"power_consumed"
21 ATTR_IN_USE =
"in_use"
23 LOAD_POWER =
"load_power"
24 POWER_CONSUMED =
"power_consumed"
25 ENERGY_CONSUMED =
"energy_consumed"
31 config_entry: ConfigEntry,
32 async_add_entities: AddEntitiesCallback,
34 """Perform the setup for Xiaomi devices."""
36 gateway = hass.data[DOMAIN][GATEWAYS_KEY][config_entry.entry_id]
37 for device
in gateway.devices[
"switch"]:
38 model = device[
"model"]
40 if "proto" not in device
or int(device[
"proto"][0:1]) == 1:
43 data_key =
"channel_0"
46 device,
"Plug", data_key,
True, gateway, config_entry
57 device,
"Wall Switch",
"channel_0",
False, gateway, config_entry
68 device,
"Wall Switch LN",
"channel_0",
False, gateway, config_entry
106 "Wall Switch LN Left",
116 "Wall Switch LN Right",
123 elif model
in (
"86plug",
"ctrl_86plug",
"ctrl_86plug.aq1"):
124 if "proto" not in device
or int(device[
"proto"][0:1]) == 1:
127 data_key =
"channel_0"
130 device,
"Wall Plug", data_key,
True, gateway, config_entry
137 """Representation of a XiaomiPlug."""
144 supports_power_consumption,
148 """Initialize the XiaomiPlug."""
156 super().
__init__(device, name, xiaomi_hub, config_entry)
160 """Return the icon to use in the frontend, if any."""
162 return "mdi:power-plug"
163 return "mdi:power-socket"
167 """Return true if it is on."""
172 """Return the state attributes."""
175 ATTR_IN_USE: self.
_in_use_in_use,
181 attrs.update(super().extra_state_attributes)
185 """Turn the switch on."""
191 """Turn the switch off."""
197 """Parse data sent by gateway."""
203 for key
in (POWER_CONSUMED, ENERGY_CONSUMED):
208 if LOAD_POWER
in data:
211 value = data.get(self.
_data_key_data_key)
212 if value
not in [
"on",
"off"]:
215 state = value ==
"on"
222 """Get data from hub."""
223 _LOGGER.debug(
"Update data from hub: %s", self.
_name_name)
def extra_state_attributes(self)
None turn_on(self, **Any kwargs)
def parse_data(self, data, raw_data)
def __init__(self, device, name, data_key, supports_power_consumption, xiaomi_hub, config_entry)
_supports_power_consumption
None turn_off(self, **Any kwargs)
None schedule_update_ha_state(self, bool force_refresh=False)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)