Feat/self.gui.connected (#2682)

* expose gui connection status

* gui.status.request.response

Co-authored-by: jarbasal <jarbasai@mailfence.com>
pull/2697/head
JarbasAI 2020-09-16 08:32:46 +01:00 committed by GitHub
parent 39a2d9cf21
commit 4d3cd33d4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -104,6 +104,7 @@ class Enclosure:
self.bus.on("gui.page.delete", self.on_gui_delete_page)
self.bus.on("gui.clear.namespace", self.on_gui_delete_namespace)
self.bus.on("gui.event.send", self.on_gui_send_event)
self.bus.on("gui.status.request", self.handle_gui_status_request)
def run(self):
try:
@ -114,6 +115,16 @@ class Enclosure:
######################################################################
# GUI client API
@property
def gui_connected(self):
"""Returns True if at least 1 gui is connected, else False"""
return len(GUIWebsocketHandler.clients) > 0
def handle_gui_status_request(self, message):
"""Reply to gui status request, allows querying if a gui is
connected using the message bus"""
self.bus.emit(message.reply("gui.status.request.response",
{"connected": self.gui_connected}))
def send(self, msg_dict):
""" Send to all registered GUIs. """

View File

@ -39,6 +39,16 @@ class SkillGUI:
self.on_gui_changed_callback = None
self.config = Configuration.get()
@property
def connected(self):
"""Returns True if at least 1 gui is connected, else False"""
if self.skill.bus:
reply = self.skill.bus.wait_for_response(
Message("gui.status.request"), "gui.status.request.response")
if reply:
return reply.data["connected"]
return False
@property
def remote_url(self):
"""Returns configuration value for url of remote-server."""