From 505565d3a6befaba3b57c87c22333b0e965ab347 Mon Sep 17 00:00:00 2001 From: Hemna Date: Sat, 23 Nov 2024 09:12:11 -0500 Subject: [PATCH] Added client_exists() for client factory This patch adds a method in the factory to detect if we have created the client yet or not. --- aprsd/client/factory.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/aprsd/client/factory.py b/aprsd/client/factory.py index cce1480..a179dca 100644 --- a/aprsd/client/factory.py +++ b/aprsd/client/factory.py @@ -42,6 +42,7 @@ class Client(Protocol): class ClientFactory: _instance = None clients = [] + client = None def __new__(cls, *args, **kwargs): """This magic turns this into a singleton.""" @@ -62,9 +63,13 @@ class ClientFactory: def create(self, key=None): for client in self.clients: if client.is_enabled(): - return client() + self.client = client() + return self.client raise Exception("No client is configured!!") + def client_exists(self): + return bool(self.client) + def is_client_enabled(self): """Make sure at least one client is enabled.""" enabled = False