Add get_config (#2627)
This commit is contained in:
parent
b4990d61f9
commit
fed2c33b54
2 changed files with 19 additions and 1 deletions
|
@ -21,7 +21,7 @@ import homeassistant.bootstrap as bootstrap
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
HTTP_HEADER_HA_AUTH, SERVER_PORT, URL_API, URL_API_EVENT_FORWARD,
|
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,
|
URL_API_SERVICES_SERVICE, URL_API_STATES, URL_API_STATES_ENTITY,
|
||||||
HTTP_HEADER_CONTENT_TYPE, CONTENT_TYPE_JSON)
|
HTTP_HEADER_CONTENT_TYPE, CONTENT_TYPE_JSON)
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
|
@ -524,3 +524,17 @@ def call_service(api, domain, service, service_data=None, timeout=5):
|
||||||
|
|
||||||
except HomeAssistantError:
|
except HomeAssistantError:
|
||||||
_LOGGER.exception("Error calling service")
|
_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 {}
|
||||||
|
|
|
@ -295,3 +295,7 @@ class TestRemoteClasses(unittest.TestCase):
|
||||||
hass.pool.block_till_done()
|
hass.pool.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(test_value))
|
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))
|
||||||
|
|
Loading…
Add table
Reference in a new issue