2017-02-12 19:31:46 +00:00
|
|
|
"""Component to interact with Hassbian tools."""
|
|
|
|
|
2019-05-21 05:21:31 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2017-02-12 19:31:46 +00:00
|
|
|
from homeassistant.components.http import HomeAssistantView
|
|
|
|
from homeassistant.config import async_check_ha_config_file
|
2019-05-21 05:21:31 +00:00
|
|
|
from homeassistant.components import websocket_api
|
2017-02-12 19:31:46 +00:00
|
|
|
|
|
|
|
|
2018-10-01 06:50:05 +00:00
|
|
|
async def async_setup(hass):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Set up the Hassbian config."""
|
2017-02-12 19:31:46 +00:00
|
|
|
hass.http.register_view(CheckConfigView)
|
2019-05-21 05:21:31 +00:00
|
|
|
hass.components.websocket_api.async_register_command(websocket_core_update)
|
2017-02-12 19:31:46 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
class CheckConfigView(HomeAssistantView):
|
|
|
|
"""Hassbian packages endpoint."""
|
|
|
|
|
|
|
|
url = '/api/config/core/check_config'
|
|
|
|
name = 'api:config:core:check_config'
|
|
|
|
|
2018-10-01 06:50:05 +00:00
|
|
|
async def post(self, request):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Validate configuration and return results."""
|
2018-10-01 06:50:05 +00:00
|
|
|
errors = await async_check_ha_config_file(request.app['hass'])
|
2017-02-12 19:31:46 +00:00
|
|
|
|
|
|
|
state = 'invalid' if errors else 'valid'
|
|
|
|
|
|
|
|
return self.json({
|
|
|
|
"result": state,
|
|
|
|
"errors": errors,
|
|
|
|
})
|
2019-05-21 05:21:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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'])
|