hass-core/homeassistant/components/websocket_api/messages.py
Ville Skyttä f259ff17d5
Type hint additions (#26831)
* Type hint additions

* Remove optional from sidebar_icon comment

Co-Authored-By: Franck Nijhof <frenck@frenck.nl>

* Remove optional from sidebar_title comment

Co-Authored-By: Franck Nijhof <frenck@frenck.nl>

* Fix issues after rebase and mypy 0.730
2019-09-29 20:07:49 +03:00

39 lines
1,020 B
Python

"""Message templates for websocket commands."""
import voluptuous as vol
from homeassistant.helpers import config_validation as cv
from . import const
# mypy: allow-untyped-defs
# Minimal requirements of a message
MINIMAL_MESSAGE_SCHEMA = vol.Schema(
{vol.Required("id"): cv.positive_int, vol.Required("type"): cv.string},
extra=vol.ALLOW_EXTRA,
)
# Base schema to extend by message handlers
BASE_COMMAND_MESSAGE_SCHEMA = vol.Schema({vol.Required("id"): cv.positive_int})
def result_message(iden, result=None):
"""Return a success result message."""
return {"id": iden, "type": const.TYPE_RESULT, "success": True, "result": result}
def error_message(iden, code, message):
"""Return an error result message."""
return {
"id": iden,
"type": const.TYPE_RESULT,
"success": False,
"error": {"code": code, "message": message},
}
def event_message(iden, event):
"""Return an event message."""
return {"id": iden, "type": "event", "event": event}