Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 22 additions & 27 deletions homeassistant/components/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,26 @@
ON_DEMAND = ('zwave',)


@asyncio.coroutine
def async_setup(hass, config):
async def async_setup(hass, config):
"""Set up the config component."""
yield from hass.components.frontend.async_register_built_in_panel(
await hass.components.frontend.async_register_built_in_panel(
'config', 'config', 'mdi:settings')

@asyncio.coroutine
def setup_panel(panel_name):
async def setup_panel(panel_name):
"""Set up a panel."""
panel = yield from async_prepare_setup_platform(
panel = await async_prepare_setup_platform(
hass, config, DOMAIN, panel_name)

if not panel:
return

success = yield from panel.async_setup(hass)
success = await panel.async_setup(hass)

if success:
key = '{}.{}'.format(DOMAIN, panel_name)
hass.bus.async_fire(EVENT_COMPONENT_LOADED, {ATTR_COMPONENT: key})
hass.config.components.add(key)

tasks = [setup_panel(panel_name) for panel_name in SECTIONS]

for panel_name in ON_DEMAND:
if panel_name in hass.config.components:
tasks.append(setup_panel(panel_name))

if tasks:
yield from asyncio.wait(tasks, loop=hass.loop)

@callback
def component_loaded(event):
"""Respond to components being loaded."""
Expand All @@ -58,6 +47,15 @@ def component_loaded(event):

hass.bus.async_listen(EVENT_COMPONENT_LOADED, component_loaded)

tasks = [setup_panel(panel_name) for panel_name in SECTIONS]

for panel_name in ON_DEMAND:
if panel_name in hass.config.components:
tasks.append(setup_panel(panel_name))

if tasks:
await asyncio.wait(tasks, loop=hass.loop)

return True


Expand Down Expand Up @@ -86,23 +84,21 @@ def _write_value(self, hass, data, config_key, new_value):
"""Set value."""
raise NotImplementedError

@asyncio.coroutine
def get(self, request, config_key):
async def get(self, request, config_key):
"""Fetch device specific config."""
hass = request.app['hass']
current = yield from self.read_config(hass)
current = await self.read_config(hass)
value = self._get_value(hass, current, config_key)

if value is None:
return self.json_message('Resource not found', 404)

return self.json(value)

@asyncio.coroutine
def post(self, request, config_key):
async def post(self, request, config_key):
"""Validate config and return results."""
try:
data = yield from request.json()
data = await request.json()
except ValueError:
return self.json_message('Invalid JSON specified', 400)

Expand All @@ -121,10 +117,10 @@ def post(self, request, config_key):
hass = request.app['hass']
path = hass.config.path(self.path)

current = yield from self.read_config(hass)
current = await self.read_config(hass)
self._write_value(hass, current, config_key, data)

yield from hass.async_add_job(_write, path, current)
await hass.async_add_job(_write, path, current)

if self.post_write_hook is not None:
hass.async_add_job(self.post_write_hook(hass))
Expand All @@ -133,10 +129,9 @@ def post(self, request, config_key):
'result': 'ok',
})

@asyncio.coroutine
def read_config(self, hass):
async def read_config(self, hass):
"""Read the config."""
current = yield from hass.async_add_job(
current = await hass.async_add_job(
_read, hass.config.path(self.path))
if not current:
current = self._empty_config()
Expand Down