-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ Added support for simple config flow allowing the integration to be configured either via YAML or UI + `test/conftest.py`: added custom fixture inheriting from `enable_custom_integrations` one from Pytest HASS package so that custom integrations are initialized during tests * `tox.ini`: Explicitly added `aiohttp_cors` package required for `http` component being dependency during tests * Updated comments * `manifest.json`: Updated `integration_type` to `service` otherwise it won't get properly added via UI
- Loading branch information
Showing
9 changed files
with
159 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
ConfigFlow support for the custom component. | ||
""" | ||
from __future__ import annotations | ||
from typing import Any | ||
|
||
from homeassistant import config_entries | ||
from homeassistant.data_entry_flow import FlowResult | ||
|
||
from .const import DOMAIN, TITLE | ||
|
||
|
||
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): | ||
""" | ||
Handles the config flow for the integration. | ||
""" | ||
VERSION = 1 | ||
|
||
async def async_step_user( | ||
self, _user_input: dict[str, Any] | None = None | ||
) -> FlowResult: | ||
""" | ||
Handles adding single entry upon user confirmation. | ||
""" | ||
# Only single entry allowed | ||
if self._async_current_entries(): | ||
return self.async_abort(reason="single_instance_allowed") | ||
|
||
return self.async_create_entry(title=TITLE, data={}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
""" | ||
Constants for custom integration. | ||
""" | ||
|
||
DOMAIN = 'oidc_userinfo' | ||
TITLE = 'OIDC UserInfo endpoint' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"config": { | ||
"step": { | ||
"user": { | ||
"description": "Do you want to add OIDC UserInfo to Home Assistant?" | ||
} | ||
}, | ||
"abort": { | ||
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
""" | ||
Pytest configuration and fixtures | ||
""" | ||
import pytest | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
# pylint: disable=unused-argument | ||
def auto_enable_custom_integrations(enable_custom_integrations): | ||
""" | ||
Automatically uses `enable_custom_integrations` Homeassistant fixture, | ||
since it is required for custom integrations to be loaded during tests. | ||
""" | ||
yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
Tests config flow for the custom component. | ||
""" | ||
from homeassistant.data_entry_flow import FlowResultType | ||
from homeassistant.config_entries import ConfigEntry | ||
|
||
from custom_components.oidc_userinfo.const import DOMAIN | ||
|
||
|
||
async def test_config_flow(hass): | ||
""" | ||
Tests config flow with no options. | ||
""" | ||
# Initial step | ||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, | ||
context={"source": "user"}, | ||
) | ||
|
||
# Verify it results in creating entity of proper type/domain | ||
assert result['type'] == FlowResultType.CREATE_ENTRY | ||
assert isinstance(result['result'], ConfigEntry) | ||
assert result['result'].domain == DOMAIN | ||
|
||
# Attemting to instantiate another entry should be aborted | ||
result = await hass.config_entries.flow.async_init( | ||
DOMAIN, | ||
context={"source": "user"}, | ||
) | ||
|
||
assert result['type'] == FlowResultType.ABORT | ||
assert result['reason'] == 'single_instance_allowed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters