-
-
Notifications
You must be signed in to change notification settings - Fork 38.3k
Add Thread integration #86283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add Thread integration #86283
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,30 @@ | ||
| """The Thread integration.""" | ||
| from __future__ import annotations | ||
|
|
||
| from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers.typing import ConfigType | ||
|
|
||
| from .const import DOMAIN | ||
|
|
||
|
|
||
| async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: | ||
| """Set up the Thread integration.""" | ||
| if not hass.config_entries.async_entries(DOMAIN): | ||
| hass.async_create_task( | ||
| hass.config_entries.flow.async_init( | ||
| DOMAIN, context={"source": SOURCE_IMPORT} | ||
| ) | ||
| ) | ||
| return True | ||
|
|
||
|
|
||
| async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
| """Set up a config entry.""" | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
| """Unload a config entry.""" | ||
| return True | ||
This file contains hidden or 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,19 @@ | ||
| """Config flow for the Thread integration.""" | ||
| from __future__ import annotations | ||
|
|
||
| from homeassistant.config_entries import ConfigFlow | ||
| from homeassistant.data_entry_flow import FlowResult | ||
|
|
||
| from .const import DOMAIN | ||
|
|
||
|
|
||
| class ThreadConfigFlow(ConfigFlow, domain=DOMAIN): | ||
| """Handle a config flow for Thread.""" | ||
|
|
||
| VERSION = 1 | ||
|
|
||
| async def async_step_import( | ||
| self, import_data: dict[str, str] | None = None | ||
| ) -> FlowResult: | ||
| """Set up by import from async_setup.""" | ||
| return self.async_create_entry(title="Thread", data={}) |
This file contains hidden or 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,3 @@ | ||
| """Constants for the Thread integration.""" | ||
|
|
||
| DOMAIN = "thread" |
This file contains hidden or 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,9 @@ | ||
| { | ||
| "domain": "thread", | ||
| "name": "Thread", | ||
| "codeowners": ["@home-assistant/core"], | ||
| "config_flow": true, | ||
| "documentation": "https://www.home-assistant.io/integrations/thread", | ||
| "integration_type": "service", | ||
| "iot_class": "local_polling" | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -430,6 +430,7 @@ | |
| "tesla_wall_connector", | ||
| "thermobeacon", | ||
| "thermopro", | ||
| "thread", | ||
| "tibber", | ||
| "tile", | ||
| "tilt_ble", | ||
|
|
||
This file contains hidden or 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 hidden or 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 @@ | ||
| """Tests for the Thread integration.""" |
This file contains hidden or 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,22 @@ | ||
| """Test fixtures for the Thread integration.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from homeassistant.components import thread | ||
|
|
||
| from tests.common import MockConfigEntry | ||
|
|
||
| CONFIG_ENTRY_DATA = {} | ||
|
|
||
|
|
||
| @pytest.fixture(name="thread_config_entry") | ||
| async def thread_config_entry_fixture(hass): | ||
| """Mock Thread config entry.""" | ||
| config_entry = MockConfigEntry( | ||
| data=CONFIG_ENTRY_DATA, | ||
| domain=thread.DOMAIN, | ||
| options={}, | ||
| title="Thread", | ||
| ) | ||
| config_entry.add_to_hass(hass) | ||
| assert await hass.config_entries.async_setup(config_entry.entry_id) |
This file contains hidden or 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 @@ | ||
| """Test the Thread config flow.""" | ||
| from unittest.mock import patch | ||
|
|
||
| from homeassistant.components import thread | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.data_entry_flow import FlowResultType | ||
|
|
||
|
|
||
| async def test_import(hass: HomeAssistant) -> None: | ||
| """Test the import flow.""" | ||
| with patch( | ||
| "homeassistant.components.thread.async_setup_entry", | ||
| return_value=True, | ||
| ) as mock_setup_entry: | ||
| result = await hass.config_entries.flow.async_init( | ||
| thread.DOMAIN, context={"source": "import"} | ||
| ) | ||
|
|
||
| assert result["type"] == FlowResultType.CREATE_ENTRY | ||
| assert result["title"] == "Thread" | ||
| assert result["data"] == {} | ||
| assert result["options"] == {} | ||
| assert len(mock_setup_entry.mock_calls) == 1 | ||
|
|
||
| config_entry = hass.config_entries.async_entries(thread.DOMAIN)[0] | ||
| assert config_entry.data == {} | ||
| assert config_entry.options == {} | ||
| assert config_entry.title == "Thread" | ||
| assert config_entry.unique_id is None |
This file contains hidden or 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 @@ | ||
| """Test the Thread integration.""" | ||
|
|
||
| from homeassistant.components import thread | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.setup import async_setup_component | ||
|
|
||
|
|
||
| async def test_create_entry(hass: HomeAssistant): | ||
| """Test an entry is created by async_setup.""" | ||
| assert len(hass.config_entries.async_entries(thread.DOMAIN)) == 0 | ||
| hass.async_create_task(async_setup_component(hass, thread.DOMAIN, {})) | ||
|
MartinHjelmare marked this conversation as resolved.
Outdated
|
||
| await hass.async_block_till_done() | ||
|
|
||
| assert len(hass.config_entries.async_entries(thread.DOMAIN)) == 1 | ||
|
|
||
|
|
||
| async def test_remove_entry(hass: HomeAssistant, thread_config_entry): | ||
| """Test removing the entry.""" | ||
|
|
||
| config_entry = hass.config_entries.async_entries(thread.DOMAIN)[0] | ||
| assert await hass.config_entries.async_remove(config_entry.entry_id) == { | ||
| "require_restart": False | ||
| } | ||
|
|
||
|
|
||
| async def test_import_once(hass: HomeAssistant, thread_config_entry) -> None: | ||
| """Test only a single entry is created.""" | ||
| await hass.async_block_till_done() | ||
| assert len(hass.config_entries.async_entries(thread.DOMAIN)) == 1 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.