Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ homeassistant/components/flock/* @fabaff
homeassistant/components/flunearyou/* @bachya
homeassistant/components/foursquare/* @robbiet480
homeassistant/components/freebox/* @snoof85
homeassistant/components/frontend/* @home-assistant/core
homeassistant/components/frontend/* @home-assistant/frontend
homeassistant/components/gearbest/* @HerrHofrat
homeassistant/components/geniushub/* @zxdavb
homeassistant/components/gitter/* @fabaff
Expand Down Expand Up @@ -138,7 +138,7 @@ homeassistant/components/linux_battery/* @fabaff
homeassistant/components/liveboxplaytv/* @pschmitt
homeassistant/components/logger/* @home-assistant/core
homeassistant/components/logi_circle/* @evanjd
homeassistant/components/lovelace/* @home-assistant/core
homeassistant/components/lovelace/* @home-assistant/frontend
homeassistant/components/luci/* @fbradyirl
homeassistant/components/luftdaten/* @fabaff
homeassistant/components/mastodon/* @fabaff
Expand Down Expand Up @@ -173,8 +173,8 @@ homeassistant/components/openuv/* @bachya
homeassistant/components/openweathermap/* @fabaff
homeassistant/components/orangepi_gpio/* @pascallj
homeassistant/components/owlet/* @oblogic7
homeassistant/components/panel_custom/* @home-assistant/core
homeassistant/components/panel_iframe/* @home-assistant/core
homeassistant/components/panel_custom/* @home-assistant/frontend
homeassistant/components/panel_iframe/* @home-assistant/frontend
homeassistant/components/persistent_notification/* @home-assistant/core
homeassistant/components/philips_js/* @elupus
homeassistant/components/pi_hole/* @fabaff
Expand Down
24 changes: 24 additions & 0 deletions homeassistant/components/config/core.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
"""Component to interact with Hassbian tools."""

import voluptuous as vol

from homeassistant.components.http import HomeAssistantView
from homeassistant.config import async_check_ha_config_file
from homeassistant.components import websocket_api


async def async_setup(hass):
"""Set up the Hassbian config."""
hass.http.register_view(CheckConfigView)
hass.components.websocket_api.async_register_command(websocket_core_update)
return True


Expand All @@ -26,3 +30,23 @@ async def post(self, request):
"result": state,
"errors": errors,
})


@websocket_api.require_admin
@websocket_api.async_response
@websocket_api.websocket_command({
vol.Required('type'): 'config/core/update',
vol.Optional('latitude'): vol.Coerce(float),
vol.Optional('longitude'): vol.Coerce(float),
vol.Optional('elevation'): vol.Coerce(int),
vol.Optional('unit_system'): vol.Coerce(str),
vol.Optional('location_name'): vol.Coerce(str),
vol.Optional('time_zone'): vol.Coerce(str),
})
async def websocket_core_update(hass, connection, msg):
"""Handle request for account info."""
data = dict(msg)
data.pop('id')
data.pop('type')
await hass.config.update(**data)
connection.send_result(msg['id'])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to return something here?

79 changes: 70 additions & 9 deletions tests/components/config/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,96 @@

from homeassistant.bootstrap import async_setup_component
from homeassistant.components import config
from homeassistant.components.websocket_api.const import TYPE_RESULT
from tests.common import mock_coro


@asyncio.coroutine
def test_validate_config_ok(hass, hass_client):
async def test_validate_config_ok(hass, hass_client):
"""Test checking config."""
with patch.object(config, 'SECTIONS', ['core']):
yield from async_setup_component(hass, 'config', {})
await async_setup_component(hass, 'config', {})

yield from asyncio.sleep(0.1, loop=hass.loop)
await asyncio.sleep(0.1, loop=hass.loop)

client = yield from hass_client()
client = await hass_client()

with patch(
'homeassistant.components.config.core.async_check_ha_config_file',
return_value=mock_coro()):
resp = yield from client.post('/api/config/core/check_config')
resp = await client.post('/api/config/core/check_config')

assert resp.status == 200
result = yield from resp.json()
result = await resp.json()
assert result['result'] == 'valid'
assert result['errors'] is None

with patch(
'homeassistant.components.config.core.async_check_ha_config_file',
return_value=mock_coro('beer')):
resp = yield from client.post('/api/config/core/check_config')
resp = await client.post('/api/config/core/check_config')

assert resp.status == 200
result = yield from resp.json()
result = await resp.json()
assert result['result'] == 'invalid'
assert result['errors'] == 'beer'


async def test_websocket_core_update(hass, hass_ws_client):
"""Test core config update websocket command."""
with patch.object(config, 'SECTIONS', ['core']):
await async_setup_component(hass, 'config', {})

client = await hass_ws_client(hass)
await client.send_json({
'id': 5,
'type': 'config/core/update',
'latitude': 123,
})

msg = await client.receive_json()

assert msg['id'] == 5
assert msg['type'] == TYPE_RESULT
assert msg['success']

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please verify latitude got set, preferably test all other values too

@emontnemery emontnemery May 20, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

I had a review comment which I forgot to publish: should the new WS command config/core/update return:

  • The set value(s)
  • The updated core config

Or is it fine like it is?



async def test_websocket_core_update_not_admin(
hass, hass_ws_client, hass_admin_user):
"""Test core config fails for non admin."""
hass_admin_user.groups = []
with patch.object(config, 'SECTIONS', ['core']):
await async_setup_component(hass, 'config', {})

client = await hass_ws_client(hass)
await client.send_json({
'id': 6,
'type': 'config/core/update',
'latitude': 123,
})

msg = await client.receive_json()

assert msg['id'] == 6
assert msg['type'] == TYPE_RESULT
assert not msg['success']
assert msg['error']['code'] == 'unauthorized'


async def test_websocket_bad_core_update(hass, hass_ws_client):
"""Test core config update fails with bad parameters."""
with patch.object(config, 'SECTIONS', ['core']):
await async_setup_component(hass, 'config', {})

client = await hass_ws_client(hass)
await client.send_json({
'id': 7,
'type': 'config/core/update',
'latituude': 123,
})

msg = await client.receive_json()

assert msg['id'] == 7
assert msg['type'] == TYPE_RESULT
assert not msg['success']
assert msg['error']['code'] == 'invalid_format'