From 8e4710a2a921a4c3c0d1ac6e7985230ab203a9bc Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 8 Sep 2020 15:52:04 +0200 Subject: [PATCH] Remove deprecated Hue configuration (#39800) --- homeassistant/components/hue/__init__.py | 98 +----------------- tests/components/hue/test_init.py | 124 ----------------------- 2 files changed, 1 insertion(+), 221 deletions(-) diff --git a/homeassistant/components/hue/__init__.py b/homeassistant/components/hue/__init__.py index a99f9dd8a2a..fb277ee7a67 100644 --- a/homeassistant/components/hue/__init__.py +++ b/homeassistant/components/hue/__init__.py @@ -1,14 +1,11 @@ """Support for the Philips Hue system.""" -import ipaddress import logging from aiohue.util import normalize_bridge_id -import voluptuous as vol from homeassistant import config_entries, core from homeassistant.components import persistent_notification -from homeassistant.const import CONF_HOST -from homeassistant.helpers import config_validation as cv, device_registry as dr +from homeassistant.helpers import device_registry as dr from .bridge import HueBridge from .const import ( @@ -21,80 +18,10 @@ from .const import ( _LOGGER = logging.getLogger(__name__) -CONF_BRIDGES = "bridges" - -DATA_CONFIGS = "hue_configs" - -PHUE_CONFIG_FILE = "phue.conf" - -BRIDGE_CONFIG_SCHEMA = vol.Schema( - { - # Validate as IP address and then convert back to a string. - vol.Required(CONF_HOST): vol.All(ipaddress.ip_address, cv.string), - vol.Optional(CONF_ALLOW_UNREACHABLE): cv.boolean, - vol.Optional(CONF_ALLOW_HUE_GROUPS): cv.boolean, - vol.Optional("filename"): str, - } -) - -CONFIG_SCHEMA = vol.Schema( - vol.All( - cv.deprecated(DOMAIN, invalidation_version="0.115.0"), - { - DOMAIN: vol.Schema( - { - vol.Optional(CONF_BRIDGES): vol.All( - cv.ensure_list, - [BRIDGE_CONFIG_SCHEMA], - ) - } - ) - }, - ), - extra=vol.ALLOW_EXTRA, -) - async def async_setup(hass, config): """Set up the Hue platform.""" - conf = config.get(DOMAIN) - if conf is None: - conf = {} - hass.data[DOMAIN] = {} - hass.data[DATA_CONFIGS] = {} - - # User has not configured bridges - if CONF_BRIDGES not in conf: - return True - - bridges = conf[CONF_BRIDGES] - - configured_hosts = { - entry.data.get("host") for entry in hass.config_entries.async_entries(DOMAIN) - } - - for bridge_conf in bridges: - host = bridge_conf[CONF_HOST] - - # Store config in hass.data so the config entry can find it - hass.data[DATA_CONFIGS][host] = bridge_conf - - if host in configured_hosts: - continue - - # No existing config entry found, trigger link config flow. Because we're - # inside the setup of this component we'll have to use hass.async_add_job - # to avoid a deadlock: creating a config entry will set up the component - # but the setup would block till the entry is created! - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data={"host": bridge_conf[CONF_HOST]}, - ) - ) - return True @@ -102,8 +29,6 @@ async def async_setup_entry( hass: core.HomeAssistant, entry: config_entries.ConfigEntry ): """Set up a bridge from a config entry.""" - host = entry.data["host"] - config = hass.data[DATA_CONFIGS].get(host) # Migrate allow_unreachable from config entry data to config entry options if ( @@ -133,27 +58,6 @@ async def async_setup_entry( data.pop(CONF_ALLOW_HUE_GROUPS) hass.config_entries.async_update_entry(entry, data=data, options=options) - # Overwrite from YAML configuration - if config is not None: - options = {} - if CONF_ALLOW_HUE_GROUPS in config and ( - CONF_ALLOW_HUE_GROUPS not in entry.options - or config[CONF_ALLOW_HUE_GROUPS] != entry.options[CONF_ALLOW_HUE_GROUPS] - ): - options[CONF_ALLOW_HUE_GROUPS] = config[CONF_ALLOW_HUE_GROUPS] - - if CONF_ALLOW_UNREACHABLE in config and ( - CONF_ALLOW_UNREACHABLE not in entry.options - or config[CONF_ALLOW_UNREACHABLE] != entry.options[CONF_ALLOW_UNREACHABLE] - ): - options[CONF_ALLOW_UNREACHABLE] = config[CONF_ALLOW_UNREACHABLE] - - if options: - hass.config_entries.async_update_entry( - entry, - options={**entry.options, **options}, - ) - bridge = HueBridge(hass, entry) if not await bridge.async_setup(): diff --git a/tests/components/hue/test_init.py b/tests/components/hue/test_init.py index 1d6db3498f1..70a6c3b8756 100644 --- a/tests/components/hue/test_init.py +++ b/tests/components/hue/test_init.py @@ -31,130 +31,6 @@ async def test_setup_with_no_config(hass): assert hass.data[hue.DOMAIN] == {} -async def test_setup_defined_hosts_known_auth(hass): - """Test we don't initiate a config entry if config bridge is known.""" - MockConfigEntry(domain="hue", data={"host": "0.0.0.0"}).add_to_hass(hass) - - with patch.object(hue, "async_setup_entry", return_value=True): - assert ( - await async_setup_component( - hass, - hue.DOMAIN, - { - hue.DOMAIN: { - hue.CONF_BRIDGES: [ - { - hue.CONF_HOST: "0.0.0.0", - hue.CONF_ALLOW_HUE_GROUPS: False, - hue.CONF_ALLOW_UNREACHABLE: True, - }, - {hue.CONF_HOST: "1.1.1.1"}, - ] - } - }, - ) - is True - ) - - # Flow started for discovered bridge - assert len(hass.config_entries.flow.async_progress()) == 1 - - # Config stored for domain. - assert hass.data[hue.DATA_CONFIGS] == { - "0.0.0.0": { - hue.CONF_HOST: "0.0.0.0", - hue.CONF_ALLOW_HUE_GROUPS: False, - hue.CONF_ALLOW_UNREACHABLE: True, - }, - "1.1.1.1": {hue.CONF_HOST: "1.1.1.1"}, - } - - -async def test_setup_defined_hosts_no_known_auth(hass): - """Test we initiate config entry if config bridge is not known.""" - assert ( - await async_setup_component( - hass, - hue.DOMAIN, - { - hue.DOMAIN: { - hue.CONF_BRIDGES: { - hue.CONF_HOST: "0.0.0.0", - hue.CONF_ALLOW_HUE_GROUPS: False, - hue.CONF_ALLOW_UNREACHABLE: True, - } - } - }, - ) - is True - ) - - # Flow started for discovered bridge - assert len(hass.config_entries.flow.async_progress()) == 1 - - # Config stored for domain. - assert hass.data[hue.DATA_CONFIGS] == { - "0.0.0.0": { - hue.CONF_HOST: "0.0.0.0", - hue.CONF_ALLOW_HUE_GROUPS: False, - hue.CONF_ALLOW_UNREACHABLE: True, - } - } - - -async def test_config_passed_to_config_entry(hass): - """Test that configured options for a host are loaded via config entry.""" - entry = MockConfigEntry(domain=hue.DOMAIN, data={"host": "0.0.0.0"}) - entry.add_to_hass(hass) - mock_registry = Mock() - with patch.object(hue, "HueBridge") as mock_bridge, patch( - "homeassistant.helpers.device_registry.async_get_registry", - return_value=mock_registry, - ): - mock_bridge.return_value.async_setup = AsyncMock(return_value=True) - mock_bridge.return_value.api.config = Mock( - mac="mock-mac", - bridgeid="mock-bridgeid", - modelid="mock-modelid", - swversion="mock-swversion", - ) - # Can't set name via kwargs - mock_bridge.return_value.api.config.name = "mock-name" - assert ( - await async_setup_component( - hass, - hue.DOMAIN, - { - hue.DOMAIN: { - hue.CONF_BRIDGES: { - hue.CONF_HOST: "0.0.0.0", - hue.CONF_ALLOW_HUE_GROUPS: False, - hue.CONF_ALLOW_UNREACHABLE: True, - } - } - }, - ) - is True - ) - - assert len(mock_bridge.mock_calls) == 2 - p_hass, p_entry = mock_bridge.mock_calls[0][1] - - assert p_hass is hass - assert p_entry is entry - - assert len(mock_registry.mock_calls) == 1 - assert mock_registry.mock_calls[0][2] == { - "config_entry_id": entry.entry_id, - "connections": {("mac", "mock-mac")}, - "identifiers": {("hue", "mock-bridgeid")}, - "manufacturer": "Signify", - "name": "mock-name", - "model": "mock-modelid", - "sw_version": "mock-swversion", - } - - async def test_unload_entry(hass, mock_bridge_setup): """Test being able to unload an entry.""" entry = MockConfigEntry(domain=hue.DOMAIN, data={"host": "0.0.0.0"})