def test_state_change_on_notify_errors(self): """Test state change on notify errors.""" request_id = configurator.request_config( self.hass, "Test Request", lambda _: None) error = "Oh no bad bad bad" configurator.notify_errors(request_id, error) state = self.hass.states.all()[0] self.assertEqual(error, state.attributes.get(configurator.ATTR_ERRORS))
def fitbit_configuration_callback(fields: list[dict[str, str]]) -> None: """Handle configuration updates.""" config_path = hass.config.path(FITBIT_CONFIG_FILE) if os.path.isfile(config_path): config_file = load_json(config_path) if config_file == DEFAULT_CONFIG: error_msg = "You didn't correctly modify fitbit.conf, please try again." configurator.notify_errors(hass, _CONFIGURING["fitbit"], error_msg) else: setup_platform(hass, config, add_entities, discovery_info) else: setup_platform(hass, config, add_entities, discovery_info)
def request_oauth_completion(hass: HomeAssistant) -> None: """Request user complete Fitbit OAuth2 flow.""" if "fitbit" in _CONFIGURING: configurator.notify_errors(hass, _CONFIGURING["fitbit"], "Failed to register, please try again.") return def fitbit_configuration_callback(fields: list[dict[str, str]]) -> None: """Handle configuration updates.""" start_url = f"{get_url(hass, require_ssl=True)}{FITBIT_AUTH_START}" description = f"Please authorize Fitbit by visiting {start_url}" _CONFIGURING["fitbit"] = configurator.request_config( hass, "Fitbit", fitbit_configuration_callback, description=description, submit_caption="I have authorized Fitbit.", )
def register_account_callback(_): """Call for register the configurator.""" api.retrieve_token(frob) token = api.token if api.token is None: _LOGGER.error("Failed to register, please try again") configurator.notify_errors( hass, request_id, "Failed to register, please try again.") return stored_rtm_config.set_token(account_name, token) _LOGGER.debug("Retrieved new token from server") _create_instance( hass, account_name, api_key, shared_secret, token, stored_rtm_config, component, ) configurator.request_done(hass, request_id)
def request_configuration(hass, config, url, add_entities_callback): """Request configuration steps from the user.""" if "gpmdp" in _CONFIGURING: configurator.notify_errors( hass, _CONFIGURING["gpmdp"], "Failed to register, please try again." ) return websocket = create_connection((url), timeout=1) websocket.send( json.dumps( { "namespace": "connect", "method": "connect", "arguments": ["Home Assistant"], } ) ) def gpmdp_configuration_callback(callback_data): """Handle configuration changes.""" while True: try: msg = json.loads(websocket.recv()) except _exceptions.WebSocketConnectionClosedException: continue if msg["channel"] != "connect": continue if msg["payload"] != "CODE_REQUIRED": continue pin = callback_data.get("pin") websocket.send( json.dumps( { "namespace": "connect", "method": "connect", "arguments": ["Home Assistant", pin], } ) ) tmpmsg = json.loads(websocket.recv()) if tmpmsg["channel"] == "time": _LOGGER.error( "Error setting up GPMDP. Please pause " "the desktop player and try again" ) break if (code := tmpmsg["payload"]) == "CODE_REQUIRED": continue setup_gpmdp(hass, config, code, add_entities_callback) save_json(hass.config.path(GPMDP_CONFIG_FILE), {"CODE": code}) websocket.send( json.dumps( { "namespace": "connect", "method": "connect", "arguments": ["Home Assistant", code], } ) ) websocket.close() break
def test_notify_errors_fail_silently_on_bad_request_id(self): """Test if notify errors fails silently with a bad request id.""" configurator.notify_errors(2015, "Try this error")