Skip to content

Commit

Permalink
Added client_exists() for client factory
Browse files Browse the repository at this point in the history
This patch adds a method in the factory to detect if we have
created the client yet or not.
  • Loading branch information
hemna committed Nov 23, 2024
1 parent 95094b8 commit 505565d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion aprsd/client/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def setup_connection(self) -> None:
class ClientFactory:
_instance = None
clients = []
client = None

def __new__(cls, *args, **kwargs):
"""This magic turns this into a singleton."""
Expand All @@ -62,9 +63,13 @@ def register(self, aprsd_client: Callable):
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
Expand Down

0 comments on commit 505565d

Please sign in to comment.