Пример #1
0
async def test_state_change_on_notify_errors(hass):
    """Test state change on notify errors."""
    request_id = configurator.async_request_config(hass, "Test Request", lambda _: None)
    error = "Oh no bad bad bad"
    configurator.async_notify_errors(hass, request_id, error)

    states = hass.states.async_all()
    assert len(states) == 1
    state = states[0]
    assert state.attributes.get(configurator.ATTR_ERRORS) == error
Пример #2
0
def async_request_configuration(hass, config, host, web_root):
    """Request configuration steps from the user."""

    # We got an error if this method is called while we are configuring
    if host in _CONFIGURING:
        configurator.async_notify_errors(
            hass, _CONFIGURING[host], "Failed to register, please try again.")

        return

    async def async_configuration_callback(data):
        """Handle configuration changes."""
        api_key = data.get(CONF_API_KEY)
        sab_api = SabnzbdApi(host,
                             api_key,
                             web_root=web_root,
                             session=async_get_clientsession(hass))
        if not await async_check_sabnzbd(sab_api):
            return

        def success():
            """Signal successful setup."""
            conf = load_json(hass.config.path(CONFIG_FILE))
            conf[host] = {CONF_API_KEY: api_key}
            save_json(hass.config.path(CONFIG_FILE), conf)
            req_config = _CONFIGURING.pop(host)
            configurator.request_done(hass, req_config)

        hass.async_add_job(success)
        async_setup_sabnzbd(hass, sab_api, config,
                            config.get(CONF_NAME, DEFAULT_NAME))

    _CONFIGURING[host] = configurator.async_request_config(
        DEFAULT_NAME,
        async_configuration_callback,
        description="Enter the API Key",
        submit_caption="Confirm",
        fields=[{
            "id": CONF_API_KEY,
            "name": "API Key",
            "type": ""
        }],
    )
Пример #3
0
async def test_notify_errors_fail_silently_on_bad_request_id(hass):
    """Test if notify errors fails silently with a bad request id."""
    configurator.async_notify_errors(hass, 2015, "Try this error")