mirror of
https://github.com/craigerl/aprsd.git
synced 2026-02-17 05:23:47 -05:00
Some client and driver cleanup.
Fixed the declarations of some of the client and driver methods to be staticmethod.
This commit is contained in:
parent
e15322ede3
commit
328c027ad3
@ -38,15 +38,16 @@ class APRSDClient:
|
||||
keepalive_collector.KeepAliveCollector().register(cls)
|
||||
return cls._instance
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, auto_connect: bool = True):
|
||||
self.auto_connect = auto_connect
|
||||
self.connected = False
|
||||
self.login_status = {
|
||||
'success': False,
|
||||
'message': None,
|
||||
}
|
||||
if not self.driver:
|
||||
self.driver = DriverRegistry().get_driver()
|
||||
self.driver.setup_connection()
|
||||
self.driver = DriverRegistry().get_driver()
|
||||
if self.auto_connect:
|
||||
self.connect()
|
||||
|
||||
def stats(self, serializable=False) -> dict:
|
||||
stats = {}
|
||||
@ -54,17 +55,20 @@ class APRSDClient:
|
||||
stats = self.driver.stats(serializable=serializable)
|
||||
return stats
|
||||
|
||||
@property
|
||||
def is_enabled(self):
|
||||
if not self.driver:
|
||||
return False
|
||||
return self.driver.is_enabled()
|
||||
@staticmethod
|
||||
def is_enabled():
|
||||
for driver in DriverRegistry().drivers:
|
||||
if driver.is_enabled():
|
||||
return True
|
||||
return False
|
||||
|
||||
@property
|
||||
def is_configured(self):
|
||||
if not self.driver:
|
||||
return False
|
||||
return self.driver.is_configured()
|
||||
@staticmethod
|
||||
def is_configured():
|
||||
"""Check if ANY driver is configured."""
|
||||
for driver in DriverRegistry().drivers:
|
||||
if driver.is_configured():
|
||||
return True
|
||||
return False
|
||||
|
||||
# @property
|
||||
# def is_connected(self):
|
||||
@ -98,6 +102,11 @@ class APRSDClient:
|
||||
def is_alive(self):
|
||||
return self.driver.is_alive()
|
||||
|
||||
def connect(self):
|
||||
if not self.driver:
|
||||
self.driver = DriverRegistry().get_driver()
|
||||
self.driver.setup_connection()
|
||||
|
||||
def close(self):
|
||||
if not self.driver:
|
||||
return
|
||||
@ -109,7 +118,8 @@ class APRSDClient:
|
||||
LOG.info('Resetting client connection.')
|
||||
if self.driver:
|
||||
self.driver.close()
|
||||
self.driver.setup_connection()
|
||||
if not self.delay_connect:
|
||||
self.driver.setup_connection()
|
||||
if self.filter:
|
||||
self.driver.set_filter(self.filter)
|
||||
else:
|
||||
|
||||
@ -26,6 +26,7 @@ class APRSISDriver:
|
||||
|
||||
_client = None
|
||||
_checks = False
|
||||
connected = False
|
||||
|
||||
def __init__(self):
|
||||
max_timeout = {'hours': 0.0, 'minutes': 2, 'seconds': 0}
|
||||
@ -164,7 +165,7 @@ class APRSISDriver:
|
||||
return core.factory(args[0])
|
||||
|
||||
def consumer(self, callback: Callable, raw: bool = False):
|
||||
if self._client:
|
||||
if self._client and self.connected:
|
||||
try:
|
||||
self._client.consumer(
|
||||
callback,
|
||||
@ -177,7 +178,6 @@ class APRSISDriver:
|
||||
LOG.info(e.__cause__)
|
||||
raise e
|
||||
else:
|
||||
LOG.warning('client is None, might be resetting.')
|
||||
self.connected = False
|
||||
|
||||
def stats(self, serializable: bool = False) -> dict:
|
||||
|
||||
@ -79,7 +79,7 @@ class TCPKISSDriver:
|
||||
def transport(self) -> str:
|
||||
return client.TRANSPORT_TCPKISS
|
||||
|
||||
@classmethod
|
||||
@staticmethod
|
||||
def is_enabled(cls) -> bool:
|
||||
"""Check if KISS is enabled in configuration.
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ registry_group = cfg.OptGroup(
|
||||
aprsd_opts = [
|
||||
cfg.StrOpt(
|
||||
'callsign',
|
||||
required=True,
|
||||
default='NOCALL',
|
||||
help='Callsign to use for messages sent by APRSD',
|
||||
),
|
||||
cfg.BoolOpt(
|
||||
|
||||
@ -13,3 +13,10 @@ class ConfigOptionBogusDefaultException(Exception):
|
||||
f"Config file option '{config_option}' needs to be "
|
||||
f"changed from provided default of '{default_fail}'"
|
||||
)
|
||||
|
||||
|
||||
class APRSClientNotConfiguredException(Exception):
|
||||
"""APRS client is not configured."""
|
||||
|
||||
def __init__(self):
|
||||
self.message = 'APRS client is not configured.'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user