1 """Cover Platform for the Somfy MyLink component."""
14 CONF_REVERSED_TARGET_IDS,
21 _LOGGER = logging.getLogger(__name__)
23 MYLINK_COVER_TYPE_TO_DEVICE_CLASS = {
24 0: CoverDeviceClass.BLIND,
25 1: CoverDeviceClass.SHUTTER,
31 config_entry: ConfigEntry,
32 async_add_entities: AddEntitiesCallback,
34 """Discover and configure Somfy covers."""
35 reversed_target_ids = config_entry.options.get(CONF_REVERSED_TARGET_IDS, {})
37 data = hass.data[DOMAIN][config_entry.entry_id]
38 mylink_status = data[MYLINK_STATUS]
39 somfy_mylink = data[DATA_SOMFY_MYLINK]
42 for cover
in mylink_status[
"result"]:
44 "target_id": cover[
"targetID"],
45 "name": cover[
"name"],
46 "device_class": MYLINK_COVER_TYPE_TO_DEVICE_CLASS.get(
47 cover.get(
"type"), CoverDeviceClass.WINDOW
49 "reverse": reversed_target_ids.get(cover[
"targetID"],
False),
52 cover_list.append(
SomfyShade(somfy_mylink, **cover_config))
55 "Adding Somfy Cover: %s with targetID %s",
57 cover_config[
"target_id"],
64 """Object for controlling a Somfy cover."""
66 _attr_should_poll =
False
67 _attr_assumed_state =
True
68 _attr_has_entity_name =
True
77 device_class=CoverDeviceClass.WINDOW,
79 """Initialize the cover."""
87 identifiers={(DOMAIN, self.
_target_id_target_id)},
88 manufacturer=MANUFACTURER,
93 """Close the cover."""
108 """Open the cover."""
123 """Stop the cover."""
127 """Complete the initialization."""
132 if last_state
is not None and last_state.state
in (
136 self.
_attr_is_closed_attr_is_closed = last_state.state == CoverState.CLOSED
None async_open_cover(self, **Any kwargs)
None async_close_cover(self, **Any kwargs)
None async_stop_cover(self, **Any kwargs)
def __init__(self, somfy_mylink, target_id, name="SomfyShade", reverse=False, device_class=CoverDeviceClass.WINDOW)
None async_added_to_hass(self)
None async_write_ha_state(self)
State|None async_get_last_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)