Cleaner handling of optional dependencies

This commit is contained in:
hermlon 2024-08-28 16:01:37 +02:00
parent afe442a1fa
commit 0c837fd1f7
2 changed files with 9 additions and 5 deletions

View file

@ -49,11 +49,12 @@ from esphome.const import (
)
from esphome.core import CORE, coroutine_with_priority
DEPENDENCIES = ["network"]
# required for WifiSecureClient to have current time to validate the certificate
if CORE.is_esp8266:
DEPENDENCIES.append("time")
def DEPENDENCIES():
if CORE.is_esp8266:
# required for WifiSecureClient to have current time to validate the certificate
return ["network", "time"]
return ["network"]
def AUTO_LOAD():

View file

@ -70,7 +70,10 @@ class ComponentManifest:
@property
def dependencies(self) -> list[str]:
return getattr(self.module, "DEPENDENCIES", [])
dep = getattr(self.module, "DEPENDENCIES", [])
if callable(dep):
return dep()
return dep
@property
def conflicts_with(self) -> list[str]: