diff --git a/homeassistant/components/emulated_hue/__init__.py b/homeassistant/components/emulated_hue/__init__.py index 9c0df0f9f03..07ecb9d265a 100644 --- a/homeassistant/components/emulated_hue/__init__.py +++ b/homeassistant/components/emulated_hue/__init__.py @@ -22,7 +22,7 @@ from homeassistant.components.http import real_ip from .hue_api import ( HueUsernameView, HueAllLightsStateView, HueOneLightStateView, - HueOneLightChangeView, HueGroupView) + HueOneLightChangeView, HueGroupView, HueAllGroupsStateView) from .upnp import DescriptionXmlView, UPNPResponderThread DOMAIN = 'emulated_hue' @@ -105,6 +105,7 @@ async def async_setup(hass, yaml_config): HueAllLightsStateView(config).register(app, app.router) HueOneLightStateView(config).register(app, app.router) HueOneLightChangeView(config).register(app, app.router) + HueAllGroupsStateView(config).register(app, app.router) HueGroupView(config).register(app, app.router) upnp_listener = UPNPResponderThread( diff --git a/homeassistant/components/emulated_hue/hue_api.py b/homeassistant/components/emulated_hue/hue_api.py index 3699a45ef30..815e28b4fa4 100644 --- a/homeassistant/components/emulated_hue/hue_api.py +++ b/homeassistant/components/emulated_hue/hue_api.py @@ -56,6 +56,28 @@ class HueUsernameView(HomeAssistantView): return self.json([{'success': {'username': '12345678901234567890'}}]) +class HueAllGroupsStateView(HomeAssistantView): + """Group handler.""" + + url = '/api/{username}/groups' + name = 'emulated_hue:all_groups:state' + requires_auth = False + + def __init__(self, config): + """Initialize the instance of the view.""" + self.config = config + + @core.callback + def get(self, request, username): + """Process a request to make the Brilliant Lightpad work.""" + if not is_local(request[KEY_REAL_IP]): + return self.json_message('only local IPs allowed', + HTTP_BAD_REQUEST) + + return self.json({ + }) + + class HueGroupView(HomeAssistantView): """Group handler to get Logitech Pop working.""" diff --git a/tests/components/emulated_hue/test_hue_api.py b/tests/components/emulated_hue/test_hue_api.py index 8582f5b38cf..70fe894debf 100644 --- a/tests/components/emulated_hue/test_hue_api.py +++ b/tests/components/emulated_hue/test_hue_api.py @@ -15,7 +15,7 @@ from homeassistant.components import ( from homeassistant.components.emulated_hue import Config from homeassistant.components.emulated_hue.hue_api import ( HUE_API_STATE_ON, HUE_API_STATE_BRI, HueUsernameView, HueOneLightStateView, - HueAllLightsStateView, HueOneLightChangeView) + HueAllLightsStateView, HueOneLightChangeView, HueAllGroupsStateView) from homeassistant.const import STATE_ON, STATE_OFF HTTP_SERVER_PORT = get_test_instance_port() @@ -135,6 +135,7 @@ def hue_client(loop, hass_hue, aiohttp_client): HueAllLightsStateView(config).register(web_app, web_app.router) HueOneLightStateView(config).register(web_app, web_app.router) HueOneLightChangeView(config).register(web_app, web_app.router) + HueAllGroupsStateView(config).register(web_app, web_app.router) return loop.run_until_complete(aiohttp_client(web_app)) @@ -420,6 +421,20 @@ def test_proper_put_state_request(hue_client): assert result.status == 400 +@asyncio.coroutine +def test_get_empty_groups_state(hue_client): + """Test the request to get groups endpoint.""" + # Test proper on value parsing + result = yield from hue_client.get( + '/api/username/groups') + + assert result.status == 200 + + result_json = yield from result.json() + + assert result_json == {} + + # pylint: disable=invalid-name async def perform_put_test_on_ceiling_lights(hass_hue, hue_client, content_type='application/json'):