1 """Support for Xiaomi curtain."""
10 from .const
import DOMAIN, GATEWAYS_KEY
11 from .entity
import XiaomiDevice
13 ATTR_CURTAIN_LEVEL =
"curtain_level"
15 DATA_KEY_PROTO_V1 =
"status"
16 DATA_KEY_PROTO_V2 =
"curtain_status"
21 config_entry: ConfigEntry,
22 async_add_entities: AddEntitiesCallback,
24 """Perform the setup for Xiaomi devices."""
26 gateway = hass.data[DOMAIN][GATEWAYS_KEY][config_entry.entry_id]
27 for device
in gateway.devices[
"cover"]:
28 model = device[
"model"]
29 if model
in (
"curtain",
"curtain.aq2",
"curtain.hagl04"):
30 if "proto" not in device
or int(device[
"proto"][0:1]) == 1:
31 data_key = DATA_KEY_PROTO_V1
33 data_key = DATA_KEY_PROTO_V2
41 """Representation of a XiaomiGenericCover."""
43 def __init__(self, device, name, data_key, xiaomi_hub, config_entry):
44 """Initialize the XiaomiGenericCover."""
47 super().
__init__(device, name, xiaomi_hub, config_entry)
51 """Return the current position of the cover."""
56 """Return if the cover is closed."""
60 """Close the cover."""
72 """Move the cover to a specific position."""
73 position = kwargs.get(ATTR_POSITION)
74 if self.
_data_key_data_key == DATA_KEY_PROTO_V2:
80 """Parse data sent by gateway."""
81 if ATTR_CURTAIN_LEVEL
in data:
82 self.
_pos_pos =
int(data[ATTR_CURTAIN_LEVEL])
int|None current_cover_position(self)
def parse_data(self, data, raw_data)
def __init__(self, device, name, data_key, xiaomi_hub, config_entry)
int current_cover_position(self)
None stop_cover(self, **Any kwargs)
None open_cover(self, **Any kwargs)
None close_cover(self, **Any kwargs)
None set_cover_position(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)