Skip to content

Commit

Permalink
Move identity query under dedicated subject
Browse files Browse the repository at this point in the history
Jira ID: SCDI-40

Signed-off-by: Saku Auvinen <[email protected]>
  • Loading branch information
saauvine committed Sep 22, 2023
1 parent 26abb04 commit 0f651b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def stop(self):
self.batman.thread_running = False # thread loop disabled
self.t2.join() # wait for thread to finish


# pylint: disable=too-many-instance-attributes
class CommsController: # pylint: disable=too-few-public-methods
"""
Expand Down Expand Up @@ -99,7 +100,8 @@ def __init__(self, server: str, port: str, interval: int = 1000):
# logger for this module and derived from main logger
self.logger = self.main_logger.getChild("controller")

class CommsCsa: # pylint: disable=too-few-public-methods

class CommsCsa: # pylint: disable=too-few-public-methods
"""
Comms CSA class to storage settings for CSA for a state change
"""
Expand Down Expand Up @@ -165,6 +167,7 @@ async def reconnected_cb():
reconnected_cb=reconnected_cb,
disconnected_cb=disconnected_cb,
max_reconnect_attempts=-1)

async def handle_settings_csa_post(ret):
if ret == "OK":
ret = "ACK"
Expand Down Expand Up @@ -197,7 +200,7 @@ async def message_handler(message):
csac.delay = delay
csac.ack_sent = "status" in data

elif subject == f"comms.command.{identity}" or "GET_IDENTITY" in data:
elif subject == f"comms.command.{identity}" or subject == "comms.identity":
ret, info, resp = cc.command.handle_command(data, cc)
elif subject == f"comms.status.{identity}":
ret, info = "OK", "Returning current status"
Expand All @@ -213,7 +216,7 @@ async def message_handler(message):
'visualisation_active': cc.comms_status.is_visualisation_active,
'mesh_radio_on': cc.comms_status.is_mesh_radio_on,
'ap_radio_on': cc.comms_status.is_ap_radio_on,
'security_status': cc.comms_status.security_status }
'security_status': cc.comms_status.security_status}

if resp != "":
response['data'] = resp
Expand All @@ -223,7 +226,8 @@ async def message_handler(message):

await nats_client.subscribe(f"comms.settings.{identity}", cb=message_handler)
await nats_client.subscribe("comms.settings_csa", cb=message_handler)
await nats_client.subscribe(f"comms.command.>", cb=message_handler)
await nats_client.subscribe(f"comms.command.{identity}", cb=message_handler)
await nats_client.subscribe("comms.identity", cb=message_handler)
await nats_client.subscribe(f"comms.status.{identity}", cb=message_handler)

cc.logger.debug("comms_nats_controller Listening for requests")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async def main():

cmd_dict = {"api_version": 1, "cmd": "GET_IDENTITY"}
cmd = json.dumps(cmd_dict)
rep = await nc.request("comms.command.>",
rep = await nc.request("comms.identity",
cmd.encode(),
timeout=2)
print(rep.data)
Expand Down

0 comments on commit 0f651b4

Please sign in to comment.