Break up websocket component (#17003)

* Break up websocket component

* Lint
This commit is contained in:
Paulus Schoutsen 2018-10-01 11:21:00 +02:00 committed by GitHub
parent 9edf1e5151
commit 22a80cf733
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 1041 additions and 1003 deletions

View file

@ -0,0 +1,42 @@
"""Message templates for websocket commands."""
import voluptuous as vol
from homeassistant.helpers import config_validation as cv
from . import const
# 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,
},
}