fix(gateway): honor config-backed adapter requirements

This commit is contained in:
LeonSGP43 2026-04-22 23:49:53 +08:00
parent 77e04a29d5
commit a829f0e30d
5 changed files with 101 additions and 10 deletions

View file

@ -39,10 +39,12 @@ from gateway.platforms.base import (
logger = logging.getLogger(__name__)
def check_ha_requirements() -> bool:
def check_ha_requirements(config: Optional[PlatformConfig] = None) -> bool:
"""Check if Home Assistant dependencies are available and configured."""
if not AIOHTTP_AVAILABLE:
return False
if config is not None and config.token:
return True
if not os.getenv("HASS_TOKEN"):
return False
return True

View file

@ -50,10 +50,11 @@ _RECONNECT_MAX_DELAY = 60.0
_RECONNECT_JITTER = 0.2
def check_mattermost_requirements() -> bool:
def check_mattermost_requirements(config: Optional[PlatformConfig] = None) -> bool:
"""Return True if the Mattermost adapter can be used."""
token = os.getenv("MATTERMOST_TOKEN", "")
url = os.getenv("MATTERMOST_URL", "")
extra = getattr(config, "extra", {}) or {}
token = getattr(config, "token", None) or os.getenv("MATTERMOST_TOKEN", "")
url = extra.get("url", "") or os.getenv("MATTERMOST_URL", "")
if not token:
logger.debug("Mattermost: MATTERMOST_TOKEN not set")
return False
@ -736,4 +737,3 @@ class MattermostAdapter(BasePlatformAdapter):
await self.handle_message(msg_event)

View file

@ -149,9 +149,12 @@ def _looks_like_e164_number(value: str) -> bool:
return digits.isdigit() and 7 <= len(digits) <= 15
def check_signal_requirements() -> bool:
def check_signal_requirements(config: Optional[PlatformConfig] = None) -> bool:
"""Check if Signal is configured (has URL and account)."""
return bool(os.getenv("SIGNAL_HTTP_URL") and os.getenv("SIGNAL_ACCOUNT"))
extra = getattr(config, "extra", {}) or {}
http_url = extra.get("http_url") or os.getenv("SIGNAL_HTTP_URL")
account = extra.get("account") or os.getenv("SIGNAL_ACCOUNT")
return bool(http_url and account)
# ---------------------------------------------------------------------------