async def _async_learn_ir_command(self, command): """Learn an infrared command.""" device = self._device try: await device.async_request(device.api.enter_learning) except (BroadlinkException, OSError) as err: _LOGGER.debug("Failed to enter learning mode: %s", err) raise persistent_notification.async_create( self.hass, f"Press the '{command}' button.", title="Learn command", notification_id="learn_command", ) try: start_time = dt.utcnow() while (dt.utcnow() - start_time) < LEARNING_TIMEOUT: await asyncio.sleep(1) try: code = await device.async_request(device.api.check_data) except (ReadError, StorageError): continue return b64encode(code).decode("utf8") raise TimeoutError("No infrared code received within " f"{LEARNING_TIMEOUT.total_seconds()} seconds") finally: persistent_notification.async_dismiss( self.hass, notification_id="learn_command")
async def update(self, now=None): notice = await self.uplink.get_notifications(self.system_id) added = [k for k in notice if k not in self.notice] removed = [k for k in self.notice if k not in notice] self.notice = notice for x in added: persistent_notification.async_create( self.hass, x['info']['description'], x['info']['title'], 'nibe:{}'.format(x['notificationId'])) for x in removed: persistent_notification.async_dismiss('nibe:{}'.format( x['notificationId']))
async def test_dismiss_notification(hass): """Ensure removal of specific notification.""" notifications = hass.data[pn.DOMAIN] assert len(hass.states.async_entity_ids(pn.DOMAIN)) == 0 assert len(notifications) == 0 pn.async_create(hass, "test", notification_id="Beer 2") assert len(hass.states.async_entity_ids(pn.DOMAIN)) == 1 assert len(notifications) == 1 pn.async_dismiss(hass, notification_id="Beer 2") assert len(hass.states.async_entity_ids(pn.DOMAIN)) == 0 assert len(notifications) == 0
async def async_step_reauth_confirm(self, user_input: Optional[ConfigType] = None ) -> Dict[str, Any]: """Confirm reauth dialog.""" if user_input is None: return self.async_show_form( step_id="reauth_confirm", description_placeholders={"host": self._entry_data[CONF_HOST]}, data_schema=vol.Schema({}), errors={}, ) assert self.hass persistent_notification.async_dismiss(self.hass, "sonarr_reauth") return await self.async_step_user()
async def async_step_reauth_confirm( self, user_input: Optional[Dict[str, Any]] = None) -> Dict[str, Any]: """Confirm reauth dialog.""" if user_input is None: return self.async_show_form( step_id="reauth_confirm", description_placeholders={"account": self.entry["id"]}, data_schema=vol.Schema({}), errors={}, ) persistent_notification.async_dismiss(self.hass, "spotify_reauth") return await self.async_step_pick_implementation( user_input={"implementation": self.entry["auth_implementation"]})
async def update_notifications(self): """Update notification list.""" notice = await self.uplink.get_notifications(self.system_id) added = [k for k in notice if k not in self.notice] removed = [k for k in self.notice if k not in notice] self.notice = notice for x in added: persistent_notification.async_create( self.hass, x["info"]["description"], x["info"]["title"], "nibe:{}".format(x["notificationId"]), ) for x in removed: persistent_notification.async_dismiss( self.hass, "nibe:{}".format(x["notificationId"]))
async def test_ws_get_notifications(hass, hass_ws_client): """Test websocket endpoint for retrieving persistent notifications.""" await async_setup_component(hass, pn.DOMAIN, {}) client = await hass_ws_client(hass) await client.send_json({"id": 5, "type": "persistent_notification/get"}) msg = await client.receive_json() assert msg["id"] == 5 assert msg["type"] == TYPE_RESULT assert msg["success"] notifications = msg["result"] assert len(notifications) == 0 # Create pn.async_create(hass, "test", notification_id="Beer 2") await client.send_json({"id": 6, "type": "persistent_notification/get"}) msg = await client.receive_json() assert msg["id"] == 6 assert msg["type"] == TYPE_RESULT assert msg["success"] notifications = msg["result"] assert len(notifications) == 1 notification = notifications[0] assert notification["notification_id"] == "Beer 2" assert notification["message"] == "test" assert notification["title"] is None assert notification["status"] == pn.STATUS_UNREAD assert notification["created_at"] is not None # Mark Read await hass.services.async_call( pn.DOMAIN, "mark_read", {"notification_id": "Beer 2"} ) await client.send_json({"id": 7, "type": "persistent_notification/get"}) msg = await client.receive_json() notifications = msg["result"] assert len(notifications) == 1 assert notifications[0]["status"] == pn.STATUS_READ # Dismiss pn.async_dismiss(hass, "Beer 2") await client.send_json({"id": 8, "type": "persistent_notification/get"}) msg = await client.receive_json() notifications = msg["result"] assert len(notifications) == 0
async def async_step_reauth_confirm( self, user_input: dict[str, Any] | None = None ) -> FlowResult: """Confirm reauth dialog.""" if self.reauth_entry is None: return self.async_abort(reason="reauth_account_mismatch") if user_input is None and self.reauth_entry: return self.async_show_form( step_id="reauth_confirm", description_placeholders={"account": self.reauth_entry.data["id"]}, errors={}, ) persistent_notification.async_dismiss(self.hass, "spotify_reauth") return await self.async_step_pick_implementation( user_input={"implementation": self.reauth_entry.data["auth_implementation"]} )
async def async_step_user(self, user_input: dict | None = None): """Handle a flow initiated by the user.""" if self._async_current_entries(): return self.async_abort(reason="single_instance_allowed") persistent_notification.async_dismiss(self.hass, "cloudflare_setup") errors = {} if user_input is not None: info, errors = await self._async_validate_or_error(user_input) if not errors: self.cloudflare_config.update(user_input) self.zones = info["zones"] return await self.async_step_zone() return self.async_show_form(step_id="user", data_schema=DATA_SCHEMA, errors=errors)
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Handle removal of an entry.""" lockname = config_entry.data[CONF_LOCK_NAME] notification_id = f"{DOMAIN}_{lockname}_unload" async_create( hass, (f"Removing `{lockname}` and all of the files that were generated for " "it. This may take some time so don't panic. This message will " "automatically clear when removal is complete."), title=f"{DOMAIN.title()} - Removing `{lockname}`", notification_id=notification_id, ) unload_ok = all(await asyncio.gather(*[ hass.config_entries.async_forward_entry_unload(config_entry, platform) for platform in PLATFORMS ])) if unload_ok: # Remove all package files and the base folder if needed await hass.async_add_executor_job(delete_lock_and_base_folder, hass, config_entry) await async_reload_package_platforms(hass) # Unsubscribe to any listeners for unsub_listener in hass.data[DOMAIN][config_entry.entry_id].get( UNSUB_LISTENERS, []): unsub_listener() hass.data[DOMAIN][config_entry.entry_id].get(UNSUB_LISTENERS, []).clear() hass.data[DOMAIN].pop(config_entry.entry_id) async_dismiss(hass, notification_id) return unload_ok
async def _async_learn_rf_command(self, command): """Learn a radiofrequency command.""" device = self._device try: await device.async_request(device.api.sweep_frequency) except (BroadlinkException, OSError) as err: _LOGGER.debug("Failed to sweep frequency: %s", err) raise persistent_notification.async_create( self.hass, f"Press and hold the '{command}' button.", title="Sweep frequency", notification_id="sweep_frequency", ) try: start_time = dt.utcnow() while (dt.utcnow() - start_time) < LEARNING_TIMEOUT: await asyncio.sleep(1) found = await device.async_request(device.api.check_frequency) if found: break else: await device.async_request(device.api.cancel_sweep_frequency) raise TimeoutError( "No radiofrequency found within " f"{LEARNING_TIMEOUT.total_seconds()} seconds" ) finally: persistent_notification.async_dismiss( self.hass, notification_id="sweep_frequency" ) await asyncio.sleep(1) try: await device.async_request(device.api.find_rf_packet) except (BroadlinkException, OSError) as err: _LOGGER.debug("Failed to enter learning mode: %s", err) raise persistent_notification.async_create( self.hass, f"Press the '{command}' button again.", title="Learn command", notification_id="learn_command", ) try: start_time = dt.utcnow() while (dt.utcnow() - start_time) < LEARNING_TIMEOUT: await asyncio.sleep(1) try: code = await device.async_request(device.api.check_data) except (ReadError, StorageError): continue return b64encode(code).decode("utf8") raise TimeoutError( "No radiofrequency code received within " f"{LEARNING_TIMEOUT.total_seconds()} seconds" ) finally: persistent_notification.async_dismiss( self.hass, notification_id="learn_command" )
async def _async_stop_log_objects(call: ServiceCall) -> None: if LOG_INTERVAL_SUB not in domain_data: return persistent_notification.async_dismiss(hass, "profile_object_logging") domain_data.pop(LOG_INTERVAL_SUB)()
def async_dismiss_setup_message(hass: HomeAssistant, entry_id: str) -> None: """Dismiss persistent notification and remove QR code.""" persistent_notification.async_dismiss(hass, entry_id)
def async_dismiss_setup_message(hass, entry_id): """Dismiss persistent notification and remove QR code.""" persistent_notification.async_dismiss(hass, entry_id)