RFC: Add system health component (#20436)

* Add system health component

* Remove stale comment

* Fix confusing syntax

* Update test_init.py

* Address comments

* Lint

* Move distro check to updater

* Convert to websocket

* Lint

* Make info callback async

* Fix tests

* Fix tests

* Lint

* Catch exceptions
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2019-01-30 10:57:53 -08:00
1 parent 91aa874c0c
commit cb07ea0d60
10 files changed
+283 -65

No files matched your search

@@ -22,13 +22,22 @@ result_message = messages.result_message
async_response = decorators.async_response
require_admin = decorators.require_admin
ws_require_user = decorators.ws_require_user
websocket_command = decorators.websocket_command
# pylint: enable=invalid-name
@bind_hass
@callback
def async_register_command(hass, command, handler, schema):
def async_register_command(hass, command_or_handler, handler=None,
schema=None):
"""Register a websocket command."""
# pylint: disable=protected-access
if handler is None:
handler = command_or_handler
command = handler._ws_command
schema = handler._ws_schema
else:
command = command_or_handler
handlers = hass.data.get(DOMAIN)
if handlers is None:
handlers = hass.data[DOMAIN] = {}
@@ -98,3 +98,17 @@ def ws_require_user(
return check_current_user
return validator
def websocket_command(schema):
"""Tag a function as a websocket command."""
command = schema['type']
def decorate(func):
"""Decorate ws command function."""
# pylint: disable=protected-access
func._ws_schema = messages.BASE_COMMAND_MESSAGE_SCHEMA.extend(schema)
func._ws_command = command
return func
return decorate