fix module test

This commit is contained in:
jxxghp
2024-09-12 15:13:58 +08:00
parent 9a62feb9a9
commit 53195457c7
12 changed files with 33 additions and 18 deletions

View File

@@ -73,11 +73,14 @@ class ModuleManager(metaclass=Singleton):
测试模块
"""
if modleid not in self._running_modules:
return False, "模块未加载,请检查参数设置"
return False, ""
module = self._running_modules[modleid]
if hasattr(module, "test") \
and ObjectUtils.check_method(getattr(module, "test")):
return module.test()
result = module.test()
if not result:
return False, ""
return result
return True, "模块不支持测试"
@staticmethod

View File

@@ -42,7 +42,7 @@ class _ModuleBase(metaclass=ABCMeta):
pass
@abstractmethod
def test(self) -> Tuple[bool, str]:
def test(self) -> Optional[Tuple[bool, str]]:
"""
模块测试, 返回测试结果和错误信息
"""

View File

@@ -31,12 +31,12 @@ class EmbyModule(_ModuleBase, _MediaServerBase):
def stop(self):
pass
def test(self) -> Tuple[bool, str]:
def test(self) -> Optional[Tuple[bool, str]]:
"""
测试模块连接性
"""
if not self._servers:
return False, "未配置Emby服务器"
return None
for name, server in self._servers.items():
if server.is_inactive():
server.reconnect()

View File

@@ -44,12 +44,12 @@ class JellyfinModule(_ModuleBase, _MediaServerBase):
def stop(self):
pass
def test(self) -> Tuple[bool, str]:
def test(self) -> Optional[Tuple[bool, str]]:
"""
测试模块连接性
"""
if not self._servers:
return False, "未配置Jellyfin服务器"
return None
for name, server in self._servers.items():
if server.is_inactive():
server.reconnect()

View File

@@ -31,12 +31,12 @@ class PlexModule(_ModuleBase, _MediaServerBase):
def stop(self):
pass
def test(self) -> Tuple[bool, str]:
def test(self) -> Optional[Tuple[bool, str]]:
"""
测试模块连接性
"""
if not self._servers:
return False, "未配置Plex服务器"
return None
for name, server in self._servers.items():
if server.is_inactive():
server.reconnect()

View File

@@ -43,10 +43,12 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase):
def stop(self):
pass
def test(self) -> Tuple[bool, str]:
def test(self) -> Optional[Tuple[bool, str]]:
"""
测试模块连接性
"""
if not self._servers:
return None
for name, server in self._servers.items():
if server.is_inactive():
server.reconnect()

View File

@@ -38,10 +38,12 @@ class SlackModule(_ModuleBase, _MessageBase):
for client in self._clients.values():
client.stop()
def test(self) -> Tuple[bool, str]:
def test(self) -> Optional[Tuple[bool, str]]:
"""
测试模块连接性
"""
if not self._clients:
return None
for name, client in self._clients.items():
state = client.get_state()
if not state:

View File

@@ -20,7 +20,7 @@ class SynologyChatModule(_ModuleBase, _MessageBase):
self._configs = {}
self._clients = {}
for client in clients:
if client.type == "telegram" and client.enabled:
if client.type == "slack" and client.enabled:
self._configs[client.name] = client
self._clients[client.name] = SynologyChat(**client.config)
@@ -31,10 +31,12 @@ class SynologyChatModule(_ModuleBase, _MessageBase):
def stop(self):
pass
def test(self) -> Tuple[bool, str]:
def test(self) -> Optional[Tuple[bool, str]]:
"""
测试模块连接性
"""
if not self._clients:
return None
for name, client in self._clients.items():
state = client.get_state()
if not state:

View File

@@ -37,10 +37,12 @@ class TelegramModule(_ModuleBase, _MessageBase):
for client in self._clients.values():
client.stop()
def test(self) -> Tuple[bool, str]:
def test(self) -> Optional[Tuple[bool, str]]:
"""
测试模块连接性
"""
if not self._clients:
return None
for name, client in self._clients.items():
state = client.get_state()
if not state:

View File

@@ -40,12 +40,12 @@ class TransmissionModule(_ModuleBase, _DownloaderBase):
def stop(self):
pass
def test(self) -> Tuple[bool, str]:
def test(self) -> Optional[Tuple[bool, str]]:
"""
测试模块连接性
"""
if not self._servers:
return False, "未配置Transmission下载器"
return None
for name, server in self._servers.items():
if server.is_inactive():
server.reconnect()

View File

@@ -33,10 +33,12 @@ class VoceChatModule(_ModuleBase, _MessageBase):
def stop(self):
pass
def test(self) -> Tuple[bool, str]:
def test(self) -> Optional[Tuple[bool, str]]:
"""
测试模块连接性
"""
if not self._clients:
return None
for name, client in self._clients.items():
state = client.get_state()
if not state:

View File

@@ -34,10 +34,12 @@ class WechatModule(_ModuleBase, _MessageBase):
def stop(self):
pass
def test(self) -> Tuple[bool, str]:
def test(self) -> Optional[Tuple[bool, str]]:
"""
测试模块连接性
"""
if not self._clients:
return None
for name, client in self._clients.items():
state = client.get_state()
if not state: