From c60bb1890d8d2305052dced06fd3ce9f34f5a4bc Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 5 Jan 2022 12:16:11 +0100 Subject: [PATCH] Remove unused group config view (#63434) --- homeassistant/components/config/__init__.py | 1 - homeassistant/components/config/group.py | 40 ----- homeassistant/config.py | 1 - tests/components/config/test_group.py | 165 -------------------- 4 files changed, 207 deletions(-) delete mode 100644 homeassistant/components/config/group.py delete mode 100644 tests/components/config/test_group.py diff --git a/homeassistant/components/config/__init__.py b/homeassistant/components/config/__init__.py index e67132fef2f..e413b214187 100644 --- a/homeassistant/components/config/__init__.py +++ b/homeassistant/components/config/__init__.py @@ -25,7 +25,6 @@ SECTIONS = ( "core", "device_registry", "entity_registry", - "group", "script", "scene", ) diff --git a/homeassistant/components/config/group.py b/homeassistant/components/config/group.py deleted file mode 100644 index 8319816eb8a..00000000000 --- a/homeassistant/components/config/group.py +++ /dev/null @@ -1,40 +0,0 @@ -"""Provide configuration end points for Groups.""" -from homeassistant.components.group import ( - DOMAIN, - GROUP_SCHEMA, - GroupIntegrationRegistry, -) -from homeassistant.config import GROUP_CONFIG_PATH -from homeassistant.const import SERVICE_RELOAD -from homeassistant.core import HomeAssistant, callback -import homeassistant.helpers.config_validation as cv - -from . import EditKeyBasedConfigView - - -async def async_setup(hass): - """Set up the Group config API.""" - - async def hook(action, config_key): - """post_write_hook for Config View that reloads groups.""" - await hass.services.async_call(DOMAIN, SERVICE_RELOAD) - - hass.http.register_view( - EditKeyBasedConfigView( - "group", - "config", - GROUP_CONFIG_PATH, - cv.slug, - GROUP_SCHEMA, - post_write_hook=hook, - ) - ) - return True - - -@callback -def async_describe_on_off_states( - hass: HomeAssistant, registry: GroupIntegrationRegistry -) -> None: - """Describe group on off states.""" - return diff --git a/homeassistant/config.py b/homeassistant/config.py index 448d1d4c637..8e6c4657f39 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -74,7 +74,6 @@ VERSION_FILE = ".HA_VERSION" CONFIG_DIR_NAME = ".homeassistant" DATA_CUSTOMIZE = "hass_customize" -GROUP_CONFIG_PATH = "groups.yaml" AUTOMATION_CONFIG_PATH = "automations.yaml" SCRIPT_CONFIG_PATH = "scripts.yaml" SCENE_CONFIG_PATH = "scenes.yaml" diff --git a/tests/components/config/test_group.py b/tests/components/config/test_group.py deleted file mode 100644 index 4d1d28020bb..00000000000 --- a/tests/components/config/test_group.py +++ /dev/null @@ -1,165 +0,0 @@ -"""Test Group config panel.""" -from http import HTTPStatus -import json -from pathlib import Path -from unittest.mock import AsyncMock, patch - -from homeassistant.bootstrap import async_setup_component -from homeassistant.components import config -from homeassistant.components.config import group -from homeassistant.util.file import write_utf8_file -from homeassistant.util.yaml import dump, load_yaml - -VIEW_NAME = "api:config:group:config" - - -async def test_get_device_config(hass, hass_client): - """Test getting device config.""" - with patch.object(config, "SECTIONS", ["group"]): - await async_setup_component(hass, "config", {}) - - client = await hass_client() - - def mock_read(path): - """Mock reading data.""" - return {"hello.beer": {"free": "beer"}, "other.entity": {"do": "something"}} - - with patch("homeassistant.components.config._read", mock_read): - resp = await client.get("/api/config/group/config/hello.beer") - - assert resp.status == HTTPStatus.OK - result = await resp.json() - - assert result == {"free": "beer"} - - -async def test_update_device_config(hass, hass_client): - """Test updating device config.""" - with patch.object(config, "SECTIONS", ["group"]): - await async_setup_component(hass, "config", {}) - - client = await hass_client() - - orig_data = { - "hello.beer": {"ignored": True}, - "other.entity": {"polling_intensity": 2}, - } - - def mock_read(path): - """Mock reading data.""" - return orig_data - - written = [] - - def mock_write(path, data): - """Mock writing data.""" - written.append(data) - - mock_call = AsyncMock() - - with patch("homeassistant.components.config._read", mock_read), patch( - "homeassistant.components.config._write", mock_write - ), patch.object(hass.services, "async_call", mock_call): - resp = await client.post( - "/api/config/group/config/hello_beer", - data=json.dumps( - {"name": "Beer", "entities": ["light.top", "light.bottom"]} - ), - ) - await hass.async_block_till_done() - - assert resp.status == HTTPStatus.OK - result = await resp.json() - assert result == {"result": "ok"} - - orig_data["hello_beer"]["name"] = "Beer" - orig_data["hello_beer"]["entities"] = ["light.top", "light.bottom"] - - assert written[0] == orig_data - mock_call.assert_called_once_with("group", "reload") - - -async def test_update_device_config_invalid_key(hass, hass_client): - """Test updating device config.""" - with patch.object(config, "SECTIONS", ["group"]): - await async_setup_component(hass, "config", {}) - - client = await hass_client() - - resp = await client.post( - "/api/config/group/config/not a slug", data=json.dumps({"name": "YO"}) - ) - - assert resp.status == HTTPStatus.BAD_REQUEST - - -async def test_update_device_config_invalid_data(hass, hass_client): - """Test updating device config.""" - with patch.object(config, "SECTIONS", ["group"]): - await async_setup_component(hass, "config", {}) - - client = await hass_client() - - resp = await client.post( - "/api/config/group/config/hello_beer", data=json.dumps({"invalid_option": 2}) - ) - - assert resp.status == HTTPStatus.BAD_REQUEST - - -async def test_update_device_config_invalid_json(hass, hass_client): - """Test updating device config.""" - with patch.object(config, "SECTIONS", ["group"]): - await async_setup_component(hass, "config", {}) - - client = await hass_client() - - resp = await client.post("/api/config/group/config/hello_beer", data="not json") - - assert resp.status == HTTPStatus.BAD_REQUEST - - -async def test_update_config_write_to_temp_file(hass, hass_client, tmpdir): - """Test config with a temp file.""" - test_dir = await hass.async_add_executor_job(tmpdir.mkdir, "files") - group_yaml = Path(test_dir / "group.yaml") - - with patch.object(group, "GROUP_CONFIG_PATH", group_yaml), patch.object( - config, "SECTIONS", ["group"] - ): - await async_setup_component(hass, "config", {}) - - client = await hass_client() - - orig_data = { - "hello.beer": {"ignored": True}, - "other.entity": {"polling_intensity": 2}, - } - contents = dump(orig_data) - await hass.async_add_executor_job(write_utf8_file, group_yaml, contents) - - mock_call = AsyncMock() - - with patch.object(hass.services, "async_call", mock_call): - resp = await client.post( - "/api/config/group/config/hello_beer", - data=json.dumps( - {"name": "Beer", "entities": ["light.top", "light.bottom"]} - ), - ) - await hass.async_block_till_done() - - assert resp.status == HTTPStatus.OK - result = await resp.json() - assert result == {"result": "ok"} - - new_data = await hass.async_add_executor_job(load_yaml, group_yaml) - - assert new_data == { - **orig_data, - "hello_beer": { - "name": "Beer", - "entities": ["light.top", "light.bottom"], - }, - } - mock_call.assert_called_once_with("group", "reload")