diff --git a/homeassistant/remote.py b/homeassistant/remote.py index b2d67811f6e..409d276caf5 100644 --- a/homeassistant/remote.py +++ b/homeassistant/remote.py @@ -21,7 +21,7 @@ import homeassistant.bootstrap as bootstrap import homeassistant.core as ha from homeassistant.const import ( HTTP_HEADER_HA_AUTH, SERVER_PORT, URL_API, URL_API_EVENT_FORWARD, - URL_API_EVENTS, URL_API_EVENTS_EVENT, URL_API_SERVICES, + URL_API_EVENTS, URL_API_EVENTS_EVENT, URL_API_SERVICES, URL_API_CONFIG, URL_API_SERVICES_SERVICE, URL_API_STATES, URL_API_STATES_ENTITY, HTTP_HEADER_CONTENT_TYPE, CONTENT_TYPE_JSON) from homeassistant.exceptions import HomeAssistantError @@ -524,3 +524,17 @@ def call_service(api, domain, service, service_data=None, timeout=5): except HomeAssistantError: _LOGGER.exception("Error calling service") + + +def get_config(api): + """Return configuration.""" + try: + req = api(METHOD_GET, URL_API_CONFIG) + + return req.json() if req.status_code == 200 else {} + + except (HomeAssistantError, ValueError): + # ValueError if req.json() can't parse the JSON + _LOGGER.exception("Got unexpected configuration results") + + return {} diff --git a/tests/test_remote.py b/tests/test_remote.py index f3ec35daee5..8820d01b9be 100644 --- a/tests/test_remote.py +++ b/tests/test_remote.py @@ -295,3 +295,7 @@ class TestRemoteClasses(unittest.TestCase): hass.pool.block_till_done() self.assertEqual(1, len(test_value)) + + def test_get_config(self): + """Test the return of the configuration.""" + self.assertEqual(hass.config.as_dict(), remote.get_config(master_api))