move websocket to asynio

This commit is contained in:
Tim Bentley 2017-06-08 20:56:19 +01:00
parent 1c4f335f23
commit e7fa46b5f5
2 changed files with 6 additions and 7 deletions

View File

@ -112,8 +112,7 @@ class WebSocketServer(RegistryProperties, OpenLPMixin):
time.sleep(0.1) time.sleep(0.1)
@staticmethod @staticmethod
@asyncio.coroutine async def handle_websocket(request, path):
def handle_websocket(request, path):
""" """
Handle web socket requests and return the poll information. Handle web socket requests and return the poll information.
Check ever 0.2 seconds to get the latest position and send if changed. Check ever 0.2 seconds to get the latest position and send if changed.
@ -131,13 +130,13 @@ class WebSocketServer(RegistryProperties, OpenLPMixin):
while True: while True:
current_poll = poller.poll() current_poll = poller.poll()
if current_poll != previous_poll: if current_poll != previous_poll:
yield from request.send(json.dumps(current_poll).encode()) await request.send(json.dumps(current_poll).encode())
previous_poll = current_poll previous_poll = current_poll
yield from asyncio.sleep(0.2) await asyncio.sleep(0.2)
elif path == '/live_changed': elif path == '/live_changed':
while True: while True:
main_poll = poller.main_poll() main_poll = poller.main_poll()
if main_poll != previous_main_poll: if main_poll != previous_main_poll:
yield from request.send(main_poll) await request.send(main_poll)
previous_main_poll = main_poll previous_main_poll = main_poll
yield from asyncio.sleep(0.2) await asyncio.sleep(0.2)

View File

@ -44,7 +44,7 @@ class RemotesPlugin(Plugin, OpenLPMixin):
self.icon = build_icon(self.icon_path) self.icon = build_icon(self.icon_path)
self.weight = -1 self.weight = -1
register_endpoint(remote_endpoint) register_endpoint(remote_endpoint)
Registry().register_function('download_website', self.manage_download) Registry().register_function('download_website', self.first_time)
def initialise(self): def initialise(self):
""" """