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