Add get_config (#2627)

pull/2610/merge
Fabian Affolter 2016-07-26 17:50:38 +02:00 committed by Paulus Schoutsen
parent b4990d61f9
commit fed2c33b54
2 changed files with 19 additions and 1 deletions

View File

@ -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 {}

View File

@ -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))