Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload groups after saving a change via config API #10877

Merged
merged 1 commit into from
Dec 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions homeassistant/components/config/group.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Provide configuration end points for Groups."""
import asyncio

from homeassistant.const import SERVICE_RELOAD
from homeassistant.components.config import EditKeyBasedConfigView
from homeassistant.components.group import GROUP_SCHEMA
from homeassistant.components.group import DOMAIN, GROUP_SCHEMA
import homeassistant.helpers.config_validation as cv


Expand All @@ -12,7 +12,13 @@
@asyncio.coroutine
def async_setup(hass):
"""Set up the Group config API."""
@asyncio.coroutine
def hook(hass):
"""post_write_hook for Config View that reloads groups."""
yield from hass.services.async_call(DOMAIN, SERVICE_RELOAD)

hass.http.register_view(EditKeyBasedConfigView(
'group', 'config', CONFIG_PATH, cv.slug, GROUP_SCHEMA
'group', 'config', CONFIG_PATH, cv.slug, GROUP_SCHEMA,
post_write_hook=hook
))
return True
10 changes: 7 additions & 3 deletions tests/components/config/test_group.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Test Z-Wave config panel."""
"""Test Group config panel."""
import asyncio
import json
from unittest.mock import patch
from unittest.mock import patch, MagicMock

from homeassistant.bootstrap import async_setup_component
from homeassistant.components import config
Expand Down Expand Up @@ -66,8 +66,11 @@ def mock_write(path, data):
"""Mock writing data."""
written.append(data)

mock_call = MagicMock()

with patch('homeassistant.components.config._read', mock_read), \
patch('homeassistant.components.config._write', mock_write):
patch('homeassistant.components.config._write', mock_write), \
patch.object(hass.services, 'async_call', mock_call):
resp = yield from client.post(
'/api/config/group/config/hello_beer', data=json.dumps({
'name': 'Beer',
Expand All @@ -82,6 +85,7 @@ def mock_write(path, data):
orig_data['hello_beer']['entities'] = ['light.top', 'light.bottom']

assert written[0] == orig_data
mock_call.assert_called_once_with('group', 'reload')


@asyncio.coroutine
Expand Down