async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up the hunter douglas shades sensors.""" pv_data = hass.data[DOMAIN][entry.entry_id] room_data = pv_data[PV_ROOM_DATA] shade_data = pv_data[PV_SHADE_DATA] pv_request = pv_data[PV_API] coordinator = pv_data[COORDINATOR] device_info = pv_data[DEVICE_INFO] entities = [] for raw_shade in shade_data.values(): shade = PvShade(raw_shade, pv_request) if SHADE_BATTERY_LEVEL not in shade.raw_data: continue name_before_refresh = shade.name room_id = shade.raw_data.get(ROOM_ID_IN_SHADE) room_name = room_data.get(room_id, {}).get(ROOM_NAME_UNICODE, "") entities.append( PowerViewShadeBatterySensor( coordinator, device_info, room_name, shade, name_before_refresh ) ) async_add_entities(entities)
async def async_setup_entry(hass, entry, async_add_entities): """Set up the hunter douglas shades.""" pv_data = hass.data[DOMAIN][entry.entry_id] room_data = pv_data[PV_ROOM_DATA] shade_data = pv_data[PV_SHADE_DATA] pv_request = pv_data[PV_API] coordinator = pv_data[COORDINATOR] device_info = pv_data[DEVICE_INFO] entities = [] for raw_shade in shade_data.values(): # The shade may be out of sync with the hub # so we force a refresh when we add it if # possible shade = PvShade(raw_shade, pv_request) name_before_refresh = shade.name with suppress(asyncio.TimeoutError): async with async_timeout.timeout(1): await shade.refresh() if ATTR_POSITION_DATA not in shade.raw_data: _LOGGER.info( "The %s shade was skipped because it is missing position data", name_before_refresh, ) continue room_id = shade.raw_data.get(ROOM_ID_IN_SHADE) room_name = room_data.get(room_id, {}).get(ROOM_NAME_UNICODE, "") entities.append( PowerViewShade(coordinator, device_info, room_name, shade, name_before_refresh)) async_add_entities(entities)
async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up the hunter douglas shades sensors.""" pv_entry: PowerviewEntryData = hass.data[DOMAIN][entry.entry_id] entities = [] for raw_shade in pv_entry.shade_data.values(): shade: BaseShade = PvShade(raw_shade, pv_entry.api) if SHADE_BATTERY_LEVEL not in shade.raw_data: continue name_before_refresh = shade.name room_id = shade.raw_data.get(ROOM_ID_IN_SHADE) room_name = pv_entry.room_data.get(room_id, {}).get(ROOM_NAME_UNICODE, "") entities.append( PowerViewShadeBatterySensor( pv_entry.coordinator, pv_entry.device_info, room_name, shade, name_before_refresh, ) ) async_add_entities(entities)
async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Set up the hunter douglas shades.""" pv_entry: PowerviewEntryData = hass.data[DOMAIN][entry.entry_id] coordinator: PowerviewShadeUpdateCoordinator = pv_entry.coordinator entities: list[ShadeEntity] = [] for raw_shade in pv_entry.shade_data.values(): # The shade may be out of sync with the hub # so we force a refresh when we add it if possible shade: BaseShade = PvShade(raw_shade, pv_entry.api) name_before_refresh = shade.name with suppress(asyncio.TimeoutError): async with async_timeout.timeout(1): await shade.refresh() if ATTR_POSITION_DATA not in shade.raw_data: _LOGGER.info( "The %s shade was skipped because it is missing position data", name_before_refresh, ) continue coordinator.data.update_shade_positions(shade.raw_data) room_id = shade.raw_data.get(ROOM_ID_IN_SHADE) room_name = pv_entry.room_data.get(room_id, {}).get(ROOM_NAME_UNICODE, "") entities.extend( create_powerview_shade_entity( coordinator, pv_entry.device_info, room_name, shade, name_before_refresh ) ) async_add_entities(entities)
async def async_setup_entry(hass, entry, async_add_entities): """Set up the hunter douglas shades.""" pv_data = hass.data[DOMAIN][entry.entry_id] room_data = pv_data[PV_ROOM_DATA] shade_data = pv_data[PV_SHADE_DATA] pv_request = pv_data[PV_API] coordinator = pv_data[COORDINATOR] device_info = pv_data[DEVICE_INFO] entities = [] for raw_shade in shade_data.values(): # The shade may be out of sync with the hub # so we force a refresh when we add it if # possible shade = PvShade(raw_shade, pv_request) name_before_refresh = shade.name try: async with async_timeout.timeout(1): await shade.refresh() except asyncio.TimeoutError: # Forced refresh is not required for setup pass entities.append( PowerViewShade( shade, name_before_refresh, room_data, coordinator, device_info ) ) async_add_entities(entities)
async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: """Set up the hunter douglas advanced feature buttons.""" pv_entry: PowerviewEntryData = hass.data[DOMAIN][entry.entry_id] entities: list[ButtonEntity] = [] for raw_shade in pv_entry.shade_data.values(): shade: BaseShade = PvShade(raw_shade, pv_entry.api) name_before_refresh = shade.name room_id = shade.raw_data.get(ROOM_ID_IN_SHADE) room_name = pv_entry.room_data.get(room_id, {}).get(ROOM_NAME_UNICODE, "") for description in BUTTONS: entities.append( PowerviewButton( pv_entry.coordinator, pv_entry.device_info, room_name, shade, name_before_refresh, description, ) ) async_add_entities(entities)
async def async_setup_entry(hass, entry, async_add_entities): """Set up the hunter douglas shades sensors.""" pv_data = hass.data[DOMAIN][entry.entry_id] shade_data = pv_data[PV_SHADE_DATA] pv_request = pv_data[PV_API] coordinator = pv_data[COORDINATOR] device_info = pv_data[DEVICE_INFO] entities = [] for raw_shade in shade_data.values(): shade = PvShade(raw_shade, pv_request) if SHADE_BATTERY_LEVEL not in shade.raw_data: continue name_before_refresh = shade.name entities.append( PowerViewShadeBatterySensor(coordinator, device_info, shade, name_before_refresh)) async_add_entities(entities)