mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-24 09:36:31 +00:00
Cleanup service (#1471)
* Cleanup services on uninstall * Fix active list
This commit is contained in:
parent
8984b9aef6
commit
6ef99974cf
@ -166,8 +166,17 @@ class AddonManager(CoreSysAttributes):
|
||||
with suppress(HomeAssistantAPIError):
|
||||
await self.sys_ingress.update_hass_panel(addon)
|
||||
|
||||
# Cleanup internal data
|
||||
addon.remove_discovery()
|
||||
# Cleanup discovery data
|
||||
for message in self.sys_discovery.list_messages:
|
||||
if message.addon != addon.slug:
|
||||
continue
|
||||
self.sys_discovery.remove(message)
|
||||
|
||||
# Cleanup services data
|
||||
for service in self.sys_services.list_services:
|
||||
if addon.slug not in service.active:
|
||||
continue
|
||||
service.del_service_data(addon)
|
||||
|
||||
self.data.uninstall(addon)
|
||||
self.local.pop(slug)
|
||||
|
@ -371,13 +371,6 @@ class Addon(AddonModel):
|
||||
|
||||
raise AddonsError()
|
||||
|
||||
def remove_discovery(self):
|
||||
"""Remove all discovery message from add-on."""
|
||||
for message in self.sys_discovery.list_messages:
|
||||
if message.addon != self.slug:
|
||||
continue
|
||||
self.sys_discovery.remove(message)
|
||||
|
||||
async def remove_data(self):
|
||||
"""Remove add-on data."""
|
||||
if not self.path_data.is_dir():
|
||||
|
@ -1,4 +1,5 @@
|
||||
"""Interface for single service."""
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
import voluptuous as vol
|
||||
@ -8,7 +9,7 @@ from ..const import PROVIDE_SERVICE
|
||||
from ..coresys import CoreSys, CoreSysAttributes
|
||||
|
||||
|
||||
class ServiceInterface(CoreSysAttributes):
|
||||
class ServiceInterface(CoreSysAttributes, ABC):
|
||||
"""Interface class for service integration."""
|
||||
|
||||
def __init__(self, coresys: CoreSys):
|
||||
@ -16,19 +17,19 @@ class ServiceInterface(CoreSysAttributes):
|
||||
self.coresys: CoreSys = coresys
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def slug(self) -> str:
|
||||
"""Return slug of this service."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def _data(self) -> Dict[str, Any]:
|
||||
"""Return data of this service."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def schema(self) -> vol.Schema:
|
||||
"""Return data schema of this service."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
def providers(self) -> List[str]:
|
||||
@ -39,6 +40,11 @@ class ServiceInterface(CoreSysAttributes):
|
||||
addons.append(addon.slug)
|
||||
return addons
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def active(self) -> List[str]:
|
||||
"""Return list of addon slug they have enable that."""
|
||||
|
||||
@property
|
||||
def enabled(self) -> bool:
|
||||
"""Return True if the service is in use."""
|
||||
@ -54,10 +60,10 @@ class ServiceInterface(CoreSysAttributes):
|
||||
return self._data
|
||||
return None
|
||||
|
||||
@abstractmethod
|
||||
def set_service_data(self, addon: Addon, data: Dict[str, Any]) -> None:
|
||||
"""Write the data into service object."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@abstractmethod
|
||||
def del_service_data(self, addon: Addon) -> None:
|
||||
"""Remove the data from service object."""
|
||||
raise NotImplementedError()
|
||||
|
@ -1,6 +1,6 @@
|
||||
"""Provide the MQTT Service."""
|
||||
import logging
|
||||
from typing import Any, Dict
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from hassio.addons.addon import Addon
|
||||
from hassio.exceptions import ServicesError
|
||||
@ -59,6 +59,13 @@ class MQTTService(ServiceInterface):
|
||||
"""Return data schema of this service."""
|
||||
return SCHEMA_SERVICE_MQTT
|
||||
|
||||
@property
|
||||
def active(self) -> List[str]:
|
||||
"""Return list of addon slug they have enable that."""
|
||||
if not self.enabled:
|
||||
return []
|
||||
return [self._data[ATTR_ADDON]]
|
||||
|
||||
def set_service_data(self, addon: Addon, data: Dict[str, Any]) -> None:
|
||||
"""Write the data into service object."""
|
||||
if self.enabled:
|
||||
|
@ -1,6 +1,6 @@
|
||||
"""Provide the MySQL Service."""
|
||||
import logging
|
||||
from typing import Any, Dict
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from hassio.addons.addon import Addon
|
||||
from hassio.exceptions import ServicesError
|
||||
@ -53,6 +53,13 @@ class MySQLService(ServiceInterface):
|
||||
"""Return data schema of this service."""
|
||||
return SCHEMA_SERVICE_MYSQL
|
||||
|
||||
@property
|
||||
def active(self) -> List[str]:
|
||||
"""Return list of addon slug they have enable that."""
|
||||
if not self.enabled:
|
||||
return []
|
||||
return [self._data[ATTR_ADDON]]
|
||||
|
||||
def set_service_data(self, addon: Addon, data: Dict[str, Any]) -> None:
|
||||
"""Write the data into service object."""
|
||||
if self.enabled:
|
||||
|
Loading…
x
Reference in New Issue
Block a user