Some small improvements and refactoring.

This commit is contained in:
Johannes Findeisen 2023-02-22 16:55:06 +01:00
commit 7360ab1936
5 changed files with 11 additions and 36 deletions

View file

@ -1,23 +0,0 @@
"""
This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE.txt (MIT license).
"""
from linspector.core.service import Service
def create(configuration, environment, log):
return FritzboxPhoneStatusService(configuration, environment, log)
class FritzboxPhoneStatusService(Service):
def __init__(self, configuration, environment, log):
super().__init__(configuration, environment, log)
self.__configuration = configuration
self.__environment = environment
self.__log = log
def execute(self, **kwargs):
self.__log.debug('FritzboxPhoneStatusService object ' + str(self))
return

View file

@ -9,10 +9,10 @@ from linspector.core.service import Service
def create(configuration, environment, log):
return FritzboxUplinkService(configuration, environment, log)
return IsConnectedService(configuration, environment, log)
class FritzboxUplinkService(Service):
class IsConnectedService(Service):
def __init__(self, configuration, environment, log):
super().__init__(configuration, environment, log)
self.__configuration = configuration
@ -20,7 +20,6 @@ class FritzboxUplinkService(Service):
self.__log = log
def execute(self, identifier, service, **kwargs):
status = "NONE"
self.__log.debug('identifier=' + identifier +
'service=' + service +
' object=' + str(self) +
@ -28,11 +27,6 @@ class FritzboxUplinkService(Service):
try:
fc = FritzStatus(address=kwargs['host'],
password=kwargs['password'])
if fc.is_connected:
status = "OK"
else:
status = "ERROR"
except Exception:
self.__log.error('identifier=' + identifier +
' host=' + str(kwargs['host']) +
@ -43,5 +37,9 @@ class FritzboxUplinkService(Service):
self.__log.info('identifier=' + identifier +
' host=' + str(kwargs['host']) +
' service=' + service +
' status=' + status)
return True
' status=' + ('OK' if fc.is_connected else 'ERROR'))
if fc.is_connected:
return True
else:
return False