Add all_plugins to cleanup code (#3166)
This commit is contained in:
parent
8b93f0aee7
commit
23143aede4
|
@ -65,14 +65,10 @@ def filter_data(coresys: CoreSys, event: dict, hint: dict) -> dict:
|
|||
"images": list(coresys.resolution.evaluate.cached_images),
|
||||
},
|
||||
"versions": {
|
||||
"audio": coresys.plugins.audio.version,
|
||||
"cli": coresys.plugins.cli.version,
|
||||
"core": coresys.homeassistant.version,
|
||||
"dns": coresys.plugins.dns.version,
|
||||
"docker": coresys.docker.info.version,
|
||||
"multicast": coresys.plugins.multicast.version,
|
||||
"observer": coresys.plugins.observer.version,
|
||||
"os": coresys.os.version,
|
||||
"agent": coresys.dbus.agent.version,
|
||||
"docker": coresys.docker.info.version,
|
||||
"supervisor": coresys.supervisor.version,
|
||||
},
|
||||
"resolution": {
|
||||
|
@ -85,6 +81,11 @@ def filter_data(coresys: CoreSys, event: dict, hint: dict) -> dict:
|
|||
},
|
||||
}
|
||||
)
|
||||
|
||||
event["contexts"]["versions"].update(
|
||||
{plugin.slug: plugin.version for plugin in coresys.plugins.all_plugins}
|
||||
)
|
||||
|
||||
event.setdefault("tags", []).extend(
|
||||
[
|
||||
["installation_type", "os" if coresys.os.available else "supervised"],
|
||||
|
|
|
@ -6,6 +6,7 @@ from ..coresys import CoreSys, CoreSysAttributes
|
|||
from ..exceptions import HassioError
|
||||
from ..resolution.const import ContextType, IssueType, SuggestionType
|
||||
from .audio import PluginAudio
|
||||
from .base import PluginBase
|
||||
from .cli import PluginCli
|
||||
from .dns import PluginDns
|
||||
from .multicast import PluginMulticast
|
||||
|
@ -27,6 +28,11 @@ class PluginManager(CoreSysAttributes):
|
|||
self._observer: PluginObserver = PluginObserver(coresys)
|
||||
self._multicast: PluginMulticast = PluginMulticast(coresys)
|
||||
|
||||
@property
|
||||
def all_plugins(self) -> list[PluginBase]:
|
||||
"""Return cli handler."""
|
||||
return [self._cli, self._dns, self._audio, self._observer, self._multicast]
|
||||
|
||||
@property
|
||||
def cli(self) -> PluginCli:
|
||||
"""Return cli handler."""
|
||||
|
@ -55,13 +61,7 @@ class PluginManager(CoreSysAttributes):
|
|||
async def load(self) -> None:
|
||||
"""Load Supervisor plugins."""
|
||||
# Sequential to avoid issue on slow IO
|
||||
for plugin in (
|
||||
self.dns,
|
||||
self.audio,
|
||||
self.cli,
|
||||
self.observer,
|
||||
self.multicast,
|
||||
):
|
||||
for plugin in self.all_plugins:
|
||||
try:
|
||||
await plugin.load()
|
||||
except Exception as err: # pylint: disable=broad-except
|
||||
|
@ -76,13 +76,7 @@ class PluginManager(CoreSysAttributes):
|
|||
|
||||
# Check requirements
|
||||
await self.sys_updater.reload()
|
||||
for plugin in (
|
||||
self.dns,
|
||||
self.audio,
|
||||
self.cli,
|
||||
self.observer,
|
||||
self.multicast,
|
||||
):
|
||||
for plugin in self.all_plugins:
|
||||
# Check if need an update
|
||||
if not plugin.need_update:
|
||||
continue
|
||||
|
@ -112,24 +106,13 @@ class PluginManager(CoreSysAttributes):
|
|||
|
||||
async def repair(self) -> None:
|
||||
"""Repair Supervisor plugins."""
|
||||
await asyncio.wait(
|
||||
[
|
||||
self.dns.repair(),
|
||||
self.audio.repair(),
|
||||
self.cli.repair(),
|
||||
self.observer.repair(),
|
||||
self.multicast.repair(),
|
||||
]
|
||||
)
|
||||
await asyncio.wait([plugin.repair() for plugin in self.all_plugins])
|
||||
|
||||
async def shutdown(self) -> None:
|
||||
"""Shutdown Supervisor plugin."""
|
||||
# Sequential to avoid issue on slow IO
|
||||
for plugin in (
|
||||
self.audio,
|
||||
self.cli,
|
||||
self.multicast,
|
||||
self.dns,
|
||||
plugin for plugin in self.all_plugins if plugin.slug != "observer"
|
||||
):
|
||||
try:
|
||||
await plugin.stop()
|
||||
|
|
|
@ -27,13 +27,7 @@ class CheckPluginTrust(CheckBase):
|
|||
)
|
||||
return
|
||||
|
||||
for plugin in (
|
||||
self.sys_plugins.dns,
|
||||
self.sys_plugins.audio,
|
||||
self.sys_plugins.cli,
|
||||
self.sys_plugins.observer,
|
||||
self.sys_plugins.multicast,
|
||||
):
|
||||
for plugin in self.sys_plugins.all_plugins:
|
||||
try:
|
||||
await plugin.check_trust()
|
||||
except CodeNotaryUntrusted:
|
||||
|
@ -46,13 +40,7 @@ class CheckPluginTrust(CheckBase):
|
|||
|
||||
async def approve_check(self, reference: Optional[str] = None) -> bool:
|
||||
"""Approve check if it is affected by issue."""
|
||||
for plugin in (
|
||||
self.sys_plugins.dns,
|
||||
self.sys_plugins.audio,
|
||||
self.sys_plugins.cli,
|
||||
self.sys_plugins.observer,
|
||||
self.sys_plugins.multicast,
|
||||
):
|
||||
for plugin in self.sys_plugins.all_plugins:
|
||||
if reference != plugin.slug:
|
||||
continue
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue