mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Remove leftover hass.data[DOMAIN] usage from insteon (#168880)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
"""Support for INSTEON Modems (PLM and Hub)."""
|
||||
# pylint: disable=hass-use-runtime-data # Uses legacy hass.data[DOMAIN] pattern
|
||||
|
||||
from contextlib import suppress
|
||||
import logging
|
||||
@@ -7,7 +6,7 @@ import logging
|
||||
from pyinsteon import async_close, async_connect, devices
|
||||
from pyinsteon.constants import ReadWriteMode
|
||||
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_PLATFORM, EVENT_HOMEASSISTANT_STOP
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
@@ -34,7 +33,6 @@ from .utils import (
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
OPTIONS = "options"
|
||||
|
||||
|
||||
async def async_get_device_config(hass, config_entry):
|
||||
@@ -78,12 +76,10 @@ async def close_insteon_connection(*args):
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up an Insteon entry."""
|
||||
|
||||
if dev_path := entry.options.get(CONF_DEV_PATH):
|
||||
hass.data[DOMAIN] = {}
|
||||
hass.data[DOMAIN][CONF_DEV_PATH] = dev_path
|
||||
|
||||
api.async_load_api(hass)
|
||||
await api.async_register_insteon_frontend(hass)
|
||||
await api.async_register_insteon_frontend(
|
||||
hass, entry.options.get(CONF_DEV_PATH) or None
|
||||
)
|
||||
|
||||
if not devices.modem:
|
||||
try:
|
||||
@@ -100,19 +96,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
workdir=hass.config.config_dir, id_devices=0, load_modem_aldb=0
|
||||
)
|
||||
|
||||
# If options existed in YAML and have not already been saved to the config entry
|
||||
# add them now
|
||||
if (
|
||||
not entry.options
|
||||
and entry.source == SOURCE_IMPORT
|
||||
and hass.data.get(DOMAIN)
|
||||
and hass.data[DOMAIN].get(OPTIONS)
|
||||
):
|
||||
hass.config_entries.async_update_entry(
|
||||
entry=entry,
|
||||
options=hass.data[DOMAIN][OPTIONS],
|
||||
)
|
||||
|
||||
for device_override in entry.options.get(CONF_OVERRIDE, []):
|
||||
# Override the device default capabilities for a specific address
|
||||
address = device_override.get("address")
|
||||
|
||||
@@ -7,7 +7,7 @@ from homeassistant.components.frontend import async_panel_exists
|
||||
from homeassistant.components.http import StaticPathConfig
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
||||
from ..const import CONF_DEV_PATH, DOMAIN
|
||||
from ..const import DOMAIN
|
||||
from .aldb import (
|
||||
websocket_add_default_links,
|
||||
websocket_change_aldb_record,
|
||||
@@ -91,11 +91,12 @@ def async_load_api(hass):
|
||||
websocket_api.async_register_command(hass, websocket_get_unknown_devices)
|
||||
|
||||
|
||||
async def async_register_insteon_frontend(hass: HomeAssistant):
|
||||
async def async_register_insteon_frontend(
|
||||
hass: HomeAssistant, dev_path: str | None = None
|
||||
) -> None:
|
||||
"""Register the Insteon frontend configuration panel."""
|
||||
# Add to sidepanel if needed
|
||||
if not async_panel_exists(hass, DOMAIN):
|
||||
dev_path = hass.data.get(DOMAIN, {}).get(CONF_DEV_PATH)
|
||||
is_dev = dev_path is not None
|
||||
path = dev_path or locate_dir()
|
||||
build_id = get_build_id(is_dev)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Test the init file for the Insteon component."""
|
||||
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -78,6 +78,9 @@ async def test_import_frontend_dev_url(hass: HomeAssistant) -> None:
|
||||
patch.object(insteon, "async_connect", new=mock_successful_connection),
|
||||
patch.object(insteon, "async_close") as mock_close,
|
||||
patch.object(insteon, "devices", new=MockDevices()),
|
||||
patch.object(
|
||||
insteon.api, "async_register_insteon_frontend", new=AsyncMock()
|
||||
) as mock_register_frontend,
|
||||
):
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -85,7 +88,7 @@ async def test_import_frontend_dev_url(hass: HomeAssistant) -> None:
|
||||
{},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.data[DOMAIN][CONF_DEV_PATH] == "/some/path"
|
||||
mock_register_frontend.assert_awaited_once_with(hass, "/some/path")
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||
await hass.async_block_till_done()
|
||||
assert insteon.devices.async_save.call_count == 1
|
||||
|
||||
Reference in New Issue
Block a user