1
0
mirror of https://github.com/craigerl/aprsd.git synced 2025-09-03 13:47:51 -04:00

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.
This commit is contained in:
Hemna 2024-11-23 09:12:11 -05:00
parent 95094b874c
commit 505565d3a6

View File

@ -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