Break up websocket 2 (#17028)

* Break up websocket 2

* Lint+Test

* Lintttt

* Rename
This commit is contained in:
Paulus Schoutsen authored and Pascal Vizeli committed 2018-10-01 16:09:31 +02:00
1 parent b5e3d8c337
commit 2e6346ca43
27 files changed
+641 -568

No files matched your search

+12 -18
View File
@@ -145,7 +145,7 @@ class Panel:
index_view.get)
@callback
def to_response(self, hass, request):
def to_response(self):
"""Panel as dictionary."""
return {
'component_name': self.component_name,
@@ -485,12 +485,10 @@ def websocket_get_panels(hass, connection, msg):
Async friendly.
"""
panels = {
panel:
connection.hass.data[DATA_PANELS][panel].to_response(
connection.hass, connection.request)
panel: connection.hass.data[DATA_PANELS][panel].to_response()
for panel in connection.hass.data[DATA_PANELS]}
connection.to_write.put_nowait(websocket_api.result_message(
connection.send_message(websocket_api.result_message(
msg['id'], panels))
@@ -500,25 +498,21 @@ def websocket_get_themes(hass, connection, msg):
Async friendly.
"""
connection.to_write.put_nowait(websocket_api.result_message(msg['id'], {
connection.send_message(websocket_api.result_message(msg['id'], {
'themes': hass.data[DATA_THEMES],
'default_theme': hass.data[DATA_DEFAULT_THEME],
}))
@callback
def websocket_get_translations(hass, connection, msg):
@websocket_api.async_response
async def websocket_get_translations(hass, connection, msg):
"""Handle get translations command.
Async friendly.
"""
async def send_translations():
"""Send a translation."""
resources = await async_get_translations(hass, msg['language'])
connection.send_message_outside(websocket_api.result_message(
msg['id'], {
'resources': resources,
}
))
hass.async_add_job(send_translations())
resources = await async_get_translations(hass, msg['language'])
connection.send_message(websocket_api.result_message(
msg['id'], {
'resources': resources,
}
))