From ac3c88052307a09bcbf816925a636719bbbe8046 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Wed, 31 Aug 2022 20:46:27 +0200 Subject: [PATCH] actor update api for WS --- cbpi/__init__.py | 2 +- cbpi/controller/actor_controller.py | 8 ++++++++ cbpi/http_endpoints/http_actor.py | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index f857583..d49370d 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.0.7.a3" +__version__ = "4.0.7.a4" __codename__ = "Spring Break" diff --git a/cbpi/controller/actor_controller.py b/cbpi/controller/actor_controller.py index 1ae2a01..ae9ba9d 100644 --- a/cbpi/controller/actor_controller.py +++ b/cbpi/controller/actor_controller.py @@ -66,3 +66,11 @@ class ActorController(BasicController): self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict()) except Exception as e: logging.error("Failed to update Actor {} {}".format(id, e)) + + async def ws_actor_update(self): + try: + #await self.push_udpate() + self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda x: x.to_dict(), self.data))),self.sorting) +# self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict()) + except Exception as e: + logging.error("Failed to update Actors {}".format(e)) \ No newline at end of file diff --git a/cbpi/http_endpoints/http_actor.py b/cbpi/http_endpoints/http_actor.py index 8a6ea3b..7738a5a 100644 --- a/cbpi/http_endpoints/http_actor.py +++ b/cbpi/http_endpoints/http_actor.py @@ -24,6 +24,21 @@ class ActorHttpEndpoints(): """ return web.json_response(data=self.controller.get_state()) + @request_mapping(path="/ws_update", auth_required=False) + async def http_get_all(self, request): + """ + + --- + description: Update WS actors + tags: + - Actor + responses: + "204": + description: successful operation + """ + return web.json_response(data=await self.controller.ws_actor_update()) + + @request_mapping(path="/{id:\w+}", auth_required=False) async def http_get_one(self, request): """