diff --git a/homeassistant/components/config/__init__.py b/homeassistant/components/config/__init__.py index 96dbd79da1e0b5d480a60a9a478cebc3d42427f9..ff7b1e4d4cd7ebfe53318aebd494fde36cb3152c 100644 --- a/homeassistant/components/config/__init__.py +++ b/homeassistant/components/config/__init__.py @@ -22,7 +22,6 @@ SECTIONS = ( "automation", "config_entries", "core", - "customize", "device_registry", "entity_registry", "group", diff --git a/homeassistant/components/config/customize.py b/homeassistant/components/config/customize.py deleted file mode 100644 index 3b1122fc3a57bd3a1b82563624aea66427832cac..0000000000000000000000000000000000000000 --- a/homeassistant/components/config/customize.py +++ /dev/null @@ -1,43 +0,0 @@ -"""Provide configuration end points for Customize.""" -from homeassistant.components.homeassistant import SERVICE_RELOAD_CORE_CONFIG -from homeassistant.config import DATA_CUSTOMIZE -from homeassistant.core import DOMAIN -import homeassistant.helpers.config_validation as cv - -from . import EditKeyBasedConfigView - -CONFIG_PATH = "customize.yaml" - - -async def async_setup(hass): - """Set up the Customize 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_CORE_CONFIG) - - hass.http.register_view( - CustomizeConfigView( - "customize", "config", CONFIG_PATH, cv.entity_id, dict, post_write_hook=hook - ) - ) - - return True - - -class CustomizeConfigView(EditKeyBasedConfigView): - """Configure a list of entries.""" - - def _get_value(self, hass, data, config_key): - """Get value.""" - customize = hass.data.get(DATA_CUSTOMIZE, {}).get(config_key) or {} - return {"global": customize, "local": data.get(config_key, {})} - - def _write_value(self, hass, data, config_key, new_value): - """Set value.""" - data[config_key] = new_value - - state = hass.states.get(config_key) - state_attributes = dict(state.attributes) - state_attributes.update(new_value) - hass.states.async_set(config_key, state.state, state_attributes) diff --git a/tests/components/config/test_customize.py b/tests/components/config/test_customize.py deleted file mode 100644 index 9ea18ff2ae00be77540cceb39f533d907698c398..0000000000000000000000000000000000000000 --- a/tests/components/config/test_customize.py +++ /dev/null @@ -1,118 +0,0 @@ -"""Test Customize config panel.""" -from http import HTTPStatus -import json -from unittest.mock import patch - -import pytest - -from homeassistant.bootstrap import async_setup_component -from homeassistant.components import config -from homeassistant.config import DATA_CUSTOMIZE - - -@pytest.fixture(autouse=True) -async def setup_homeassistant(hass): - """Set up homeassistant integration.""" - assert await async_setup_component(hass, "homeassistant", {}) - - -async def test_get_entity(hass, hass_client): - """Test getting entity.""" - with patch.object(config, "SECTIONS", ["customize"]): - 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"}} - - hass.data[DATA_CUSTOMIZE] = {"hello.beer": {"cold": "beer"}} - with patch("homeassistant.components.config._read", mock_read): - resp = await client.get("/api/config/customize/config/hello.beer") - - assert resp.status == HTTPStatus.OK - result = await resp.json() - - assert result == {"local": {"free": "beer"}, "global": {"cold": "beer"}} - - -async def test_update_entity(hass, hass_client): - """Test updating entity.""" - with patch.object(config, "SECTIONS", ["customize"]): - 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) - - hass.states.async_set("hello.world", "state", {"a": "b"}) - with patch("homeassistant.components.config._read", mock_read), patch( - "homeassistant.components.config._write", mock_write - ), patch( - "homeassistant.config.async_hass_config_yaml", - return_value={}, - ): - resp = await client.post( - "/api/config/customize/config/hello.world", - 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"} - - state = hass.states.get("hello.world") - assert state.state == "state" - assert dict(state.attributes) == { - "a": "b", - "name": "Beer", - "entities": ["light.top", "light.bottom"], - } - - orig_data["hello.world"]["name"] = "Beer" - orig_data["hello.world"]["entities"] = ["light.top", "light.bottom"] - - assert written[0] == orig_data - - -async def test_update_entity_invalid_key(hass, hass_client): - """Test updating entity.""" - with patch.object(config, "SECTIONS", ["customize"]): - await async_setup_component(hass, "config", {}) - - client = await hass_client() - - resp = await client.post( - "/api/config/customize/config/not_entity", data=json.dumps({"name": "YO"}) - ) - - assert resp.status == HTTPStatus.BAD_REQUEST - - -async def test_update_entity_invalid_json(hass, hass_client): - """Test updating entity.""" - with patch.object(config, "SECTIONS", ["customize"]): - await async_setup_component(hass, "config", {}) - - client = await hass_client() - - resp = await client.post("/api/config/customize/config/hello.beer", data="not json") - - assert resp.status == HTTPStatus.BAD_REQUEST