-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Thread integration * Address review comments * Address review comments
- Loading branch information
1 parent
c15f4ad
commit 9ef86b7
Showing
12 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
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,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 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 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 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 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 |
---|---|---|
|
@@ -431,6 +431,7 @@ | |
"tesla_wall_connector", | ||
"thermobeacon", | ||
"thermopro", | ||
"thread", | ||
"tibber", | ||
"tile", | ||
"tilt_ble", | ||
|
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 @@ | ||
"""Tests for the Thread integration.""" |
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,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 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 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 | ||
assert await async_setup_component(hass, thread.DOMAIN, {}) | ||
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 |