refactor code to decrease cognitive complexity in update

This commit is contained in:
Jan Fader 2021-10-26 19:52:42 +02:00
parent fdc9b78967
commit dced20bf89
No known key found for this signature in database
GPG key ID: 1A6BDEFB0E27FA44

View file

@ -23,6 +23,10 @@ class Module(core.module.Module):
self.background = True
self.__battery_status = ""
self.__error = False
if self.__battery != "":
self.__cmd = f"solaar show '{self.__battery}'"
else:
self.__cmd = "solaar show"
@property
def __format(self):
@ -33,12 +37,8 @@ class Module(core.module.Module):
def update(self):
self.__error = False
if self.__battery != "":
cmd = f"solaar show '{self.__battery}'"
else:
cmd = "solaar show"
code, result = util.cli.execute(
cmd, ignore_errors=True, return_exitcode=True
self.__cmd, ignore_errors=True, return_exitcode=True
)
if code == 0: