mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 15:57:06 +00:00
Add config API endpoint
This commit is contained in:
parent
e07fbbbcd8
commit
ca8be5015a
@ -959,6 +959,17 @@ class Config(object):
|
|||||||
# Could not convert value to float
|
# Could not convert value to float
|
||||||
return value, unit
|
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):
|
class HomeAssistantError(Exception):
|
||||||
""" General Home Assistant exception occured. """
|
""" General Home Assistant exception occured. """
|
||||||
|
@ -15,6 +15,7 @@ import homeassistant.remote as rem
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
URL_API, URL_API_STATES, URL_API_EVENTS, URL_API_SERVICES, URL_API_STREAM,
|
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_EVENT_FORWARD, URL_API_STATES_ENTITY, URL_API_COMPONENTS,
|
||||||
|
URL_API_CONFIG,
|
||||||
EVENT_TIME_CHANGED, EVENT_HOMEASSISTANT_STOP, MATCH_ALL,
|
EVENT_TIME_CHANGED, EVENT_HOMEASSISTANT_STOP, MATCH_ALL,
|
||||||
HTTP_OK, HTTP_CREATED, HTTP_BAD_REQUEST, HTTP_NOT_FOUND,
|
HTTP_OK, HTTP_CREATED, HTTP_BAD_REQUEST, HTTP_NOT_FOUND,
|
||||||
HTTP_UNPROCESSABLE_ENTITY)
|
HTTP_UNPROCESSABLE_ENTITY)
|
||||||
@ -42,6 +43,9 @@ def setup(hass, config):
|
|||||||
# /api/stream
|
# /api/stream
|
||||||
hass.http.register_path('GET', URL_API_STREAM, _handle_get_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
|
# /states
|
||||||
hass.http.register_path('GET', URL_API_STATES, _handle_get_api_states)
|
hass.http.register_path('GET', URL_API_STATES, _handle_get_api_states)
|
||||||
hass.http.register_path(
|
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)
|
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):
|
def _handle_get_api_states(handler, path_match, data):
|
||||||
""" Returns a dict containing all entity ids and their state. """
|
""" Returns a dict containing all entity ids and their state. """
|
||||||
handler.write_json(handler.server.hass.states.all())
|
handler.write_json(handler.server.hass.states.all())
|
||||||
|
@ -111,6 +111,7 @@ SERVER_PORT = 8123
|
|||||||
URL_ROOT = "/"
|
URL_ROOT = "/"
|
||||||
URL_API = "/api/"
|
URL_API = "/api/"
|
||||||
URL_API_STREAM = "/api/stream"
|
URL_API_STREAM = "/api/stream"
|
||||||
|
URL_API_CONFIG = "/api/config"
|
||||||
URL_API_STATES = "/api/states"
|
URL_API_STATES = "/api/states"
|
||||||
URL_API_STATES_ENTITY = "/api/states/{}"
|
URL_API_STATES_ENTITY = "/api/states/{}"
|
||||||
URL_API_EVENTS = "/api/events"
|
URL_API_EVENTS = "/api/events"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user