1 """Component to interact with Hassbian tools."""
3 from __future__
import annotations
7 from aiohttp
import web
8 import voluptuous
as vol
21 """Set up the Hassbian config."""
22 hass.http.register_view(CheckConfigView)
23 websocket_api.async_register_command(hass, websocket_update_config)
24 websocket_api.async_register_command(hass, websocket_detect_config)
29 """Hassbian packages endpoint."""
31 url =
"/api/config/core/check_config"
32 name =
"api:config:core:check_config"
35 async
def post(self, request: web.Request) -> web.Response:
36 """Validate configuration and return results."""
38 res = await check_config.async_check_ha_config_file(request.app[KEY_HASS])
40 state =
"invalid" if res.errors
else "valid"
45 "errors": res.error_str
or None,
46 "warnings": res.warning_str
or None,
51 @websocket_api.require_admin
52 @websocket_api.websocket_command(
{
"type": "config/core/update",
vol.Optional("country"): cv.country,
53 vol.Optional(
"currency"): cv.currency,
54 vol.Optional(
"elevation"): int,
55 vol.Optional(
"external_url"): vol.Any(cv.url_no_path,
None),
56 vol.Optional(
"internal_url"): vol.Any(cv.url_no_path,
None),
57 vol.Optional(
"language"): cv.language,
58 vol.Optional(
"latitude"): cv.latitude,
59 vol.Optional(
"location_name"): str,
60 vol.Optional(
"longitude"): cv.longitude,
61 vol.Optional(
"radius"): cv.positive_int,
62 vol.Optional(
"time_zone"): cv.time_zone,
63 vol.Optional(
"update_units"): bool,
64 vol.Optional(
"unit_system"): unit_system.validate_unit_system,
67 @websocket_api.async_response
73 """Handle update core config command."""
78 update_units = data.pop(
"update_units",
False)
81 await hass.config.async_update(**data)
84 connection.send_result(msg[
"id"])
85 except ValueError
as err:
86 connection.send_error(msg[
"id"],
"invalid_info",
str(err))
89 @websocket_api.require_admin
90 @websocket_api.websocket_command({"type": "config/core/detect"})
91 @websocket_api.async_response
97 """Detect core config."""
99 location_info = await location.async_detect_location_info(session)
101 info: dict[str, Any] = {}
103 if location_info
is None:
104 connection.send_result(msg[
"id"], info)
109 if location_info.use_metric:
110 info[
"unit_system"] = unit_system._CONF_UNIT_SYSTEM_METRIC
112 info[
"unit_system"] = unit_system._CONF_UNIT_SYSTEM_US_CUSTOMARY
114 if location_info.latitude:
115 info[
"latitude"] = location_info.latitude
117 if location_info.longitude:
118 info[
"longitude"] = location_info.longitude
120 if location_info.time_zone:
121 info[
"time_zone"] = location_info.time_zone
123 if location_info.currency:
124 info[
"currency"] = location_info.currency
126 if location_info.country_code:
127 info[
"country"] = location_info.country_code
129 connection.send_result(msg[
"id"], info)
130
web.Response post(self, web.Request request)
None websocket_update_config(HomeAssistant hass, websocket_api.ActiveConnection connection, dict[str, Any] msg)
None websocket_detect_config(HomeAssistant hass, websocket_api.ActiveConnection connection, dict[str, Any] msg)
bool async_setup(HomeAssistant hass)
None async_update_suggested_units(HomeAssistant hass)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)