diff --git a/homeassistant/__init__.py b/homeassistant/__init__.py index 6a7b328ba40..a132f96a8a6 100644 --- a/homeassistant/__init__.py +++ b/homeassistant/__init__.py @@ -959,6 +959,17 @@ class Config(object): # Could not convert value to float return value, unit + def as_dict(self): + """ Converts config to a dictionary. """ + return { + 'latitude': self.latitude, + 'longitude': self.longitude, + 'temperature_unit': self.temperature_unit, + 'location_name': self.location_name, + 'time_zone': self.time_zone.zone, + 'components': self.components, + } + class HomeAssistantError(Exception): """ General Home Assistant exception occured. """ diff --git a/homeassistant/components/api.py b/homeassistant/components/api.py index b5cdb9cae6c..296dc809049 100644 --- a/homeassistant/components/api.py +++ b/homeassistant/components/api.py @@ -15,6 +15,7 @@ import homeassistant.remote as rem from homeassistant.const import ( URL_API, URL_API_STATES, URL_API_EVENTS, URL_API_SERVICES, URL_API_STREAM, URL_API_EVENT_FORWARD, URL_API_STATES_ENTITY, URL_API_COMPONENTS, + URL_API_CONFIG, EVENT_TIME_CHANGED, EVENT_HOMEASSISTANT_STOP, MATCH_ALL, HTTP_OK, HTTP_CREATED, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_UNPROCESSABLE_ENTITY) @@ -42,6 +43,9 @@ def setup(hass, config): # /api/stream hass.http.register_path('GET', URL_API_STREAM, _handle_get_api_stream) + # /api/config + hass.http.register_path('GET', URL_API_CONFIG, _handle_get_api_config) + # /states hass.http.register_path('GET', URL_API_STATES, _handle_get_api_states) hass.http.register_path( @@ -140,6 +144,11 @@ def _handle_get_api_stream(handler, path_match, data): hass.bus.remove_listener(MATCH_ALL, forward_events) +def _handle_get_api_config(handler, path_match, data): + """ Returns a dict containing Home Assistant config. """ + handler.write_json(handler.server.hass.config.as_dict()) + + def _handle_get_api_states(handler, path_match, data): """ Returns a dict containing all entity ids and their state. """ handler.write_json(handler.server.hass.states.all()) diff --git a/homeassistant/const.py b/homeassistant/const.py index b85340263f0..bb2e372d22c 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -111,6 +111,7 @@ SERVER_PORT = 8123 URL_ROOT = "/" URL_API = "/api/" URL_API_STREAM = "/api/stream" +URL_API_CONFIG = "/api/config" URL_API_STATES = "/api/states" URL_API_STATES_ENTITY = "/api/states/{}" URL_API_EVENTS = "/api/events"