mirror of
https://github.com/craigerl/aprsd.git
synced 2026-06-15 12:28:39 -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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user