1818from typing import Any , Final
1919
2020import aiohttp
21- from awesomeversion import AwesomeVersionCompareException
21+ from awesomeversion import AwesomeVersion , AwesomeVersionCompareException
2222from deepmerge import Merger
2323from securetar import AddFileError , atomic_contents_add , secure_path
2424import voluptuous as vol
@@ -285,28 +285,28 @@ def is_detached(self) -> bool:
285285 @property
286286 def with_icon (self ) -> bool :
287287 """Return True if an icon exists."""
288- if self .is_detached :
288+ if self .is_detached or not self . addon_store :
289289 return super ().with_icon
290290 return self .addon_store .with_icon
291291
292292 @property
293293 def with_logo (self ) -> bool :
294294 """Return True if a logo exists."""
295- if self .is_detached :
295+ if self .is_detached or not self . addon_store :
296296 return super ().with_logo
297297 return self .addon_store .with_logo
298298
299299 @property
300300 def with_changelog (self ) -> bool :
301301 """Return True if a changelog exists."""
302- if self .is_detached :
302+ if self .is_detached or not self . addon_store :
303303 return super ().with_changelog
304304 return self .addon_store .with_changelog
305305
306306 @property
307307 def with_documentation (self ) -> bool :
308308 """Return True if a documentation exists."""
309- if self .is_detached :
309+ if self .is_detached or not self . addon_store :
310310 return super ().with_documentation
311311 return self .addon_store .with_documentation
312312
@@ -316,7 +316,7 @@ def available(self) -> bool:
316316 return self ._available (self .data_store )
317317
318318 @property
319- def version (self ) -> str | None :
319+ def version (self ) -> AwesomeVersion :
320320 """Return installed version."""
321321 return self .persist [ATTR_VERSION ]
322322
@@ -464,7 +464,7 @@ def ingress_entry(self) -> str | None:
464464 return None
465465
466466 @property
467- def latest_version (self ) -> str :
467+ def latest_version (self ) -> AwesomeVersion :
468468 """Return version of add-on."""
469469 return self .data_store [ATTR_VERSION ]
470470
@@ -518,9 +518,8 @@ def ingress_url(self) -> str | None:
518518 def webui (self ) -> str | None :
519519 """Return URL to webui or None."""
520520 url = super ().webui
521- if not url :
521+ if not url or not ( webui := RE_WEBUI . match ( url )) :
522522 return None
523- webui = RE_WEBUI .match (url )
524523
525524 # extract arguments
526525 t_port = webui .group ("t_port" )
@@ -675,10 +674,9 @@ async def save_persist(self) -> None:
675674
676675 async def watchdog_application (self ) -> bool :
677676 """Return True if application is running."""
678- url = super (). watchdog
679- if not url :
677+ url = self . watchdog_url
678+ if not url or not ( application := RE_WATCHDOG . match ( url )) :
680679 return True
681- application = RE_WATCHDOG .match (url )
682680
683681 # extract arguments
684682 t_port = int (application .group ("t_port" ))
@@ -687,8 +685,10 @@ async def watchdog_application(self) -> bool:
687685 s_suffix = application .group ("s_suffix" ) or ""
688686
689687 # search host port for this docker port
690- if self .host_network :
691- port = self .ports .get (f"{ t_port } /tcp" , t_port )
688+ if self .host_network and self .ports :
689+ port = self .ports .get (f"{ t_port } /tcp" )
690+ if port is None :
691+ port = t_port
692692 else :
693693 port = t_port
694694
@@ -777,6 +777,9 @@ async def _check_ingress_port(self):
777777 )
778778 async def install (self ) -> None :
779779 """Install and setup this addon."""
780+ if not self .addon_store :
781+ raise AddonsError ("Missing from store, cannot install!" )
782+
780783 await self .sys_addons .data .install (self .addon_store )
781784 await self .load ()
782785
@@ -880,6 +883,9 @@ async def update(self) -> asyncio.Task | None:
880883 Returns a Task that completes when addon has state 'started' (see start)
881884 if it was running. Else nothing is returned.
882885 """
886+ if not self .addon_store :
887+ raise AddonsError ("Missing from store, cannot update!" )
888+
883889 old_image = self .image
884890 # Cache data to prevent races with other updates to global
885891 store = self .addon_store .clone ()
@@ -936,7 +942,9 @@ async def rebuild(self) -> asyncio.Task | None:
936942 except DockerError as err :
937943 raise AddonsError () from err
938944
939- await self .sys_addons .data .update (self .addon_store )
945+ if self .addon_store :
946+ await self .sys_addons .data .update (self .addon_store )
947+
940948 await self ._check_ingress_port ()
941949 _LOGGER .info ("Add-on '%s' successfully rebuilt" , self .slug )
942950
@@ -965,7 +973,9 @@ def write_pulse_config():
965973 await self .sys_run_in_executor (write_pulse_config )
966974 except OSError as err :
967975 if err .errno == errno .EBADMSG :
968- self .sys_resolution .unhealthy = UnhealthyReason .OSERROR_BAD_MESSAGE
976+ self .sys_resolution .add_unhealthy_reason (
977+ UnhealthyReason .OSERROR_BAD_MESSAGE
978+ )
969979 _LOGGER .error (
970980 "Add-on %s can't write pulse/client.config: %s" , self .slug , err
971981 )
@@ -1324,7 +1334,7 @@ def _addon_backup(
13241334 arcname = "config" ,
13251335 )
13261336
1327- wait_for_start : Awaitable [ None ] | None = None
1337+ wait_for_start : asyncio . Task | None = None
13281338
13291339 data = {
13301340 ATTR_USER : self .persist ,
@@ -1370,7 +1380,7 @@ async def restore(self, tar_file: tarfile.TarFile) -> asyncio.Task | None:
13701380 Returns a Task that completes when addon has state 'started' (see start)
13711381 if addon is started after restore. Else nothing is returned.
13721382 """
1373- wait_for_start : Awaitable [ None ] | None = None
1383+ wait_for_start : asyncio . Task | None = None
13741384
13751385 # Extract backup
13761386 def _extract_tarfile () -> tuple [TemporaryDirectory , dict [str , Any ]]:
@@ -1594,6 +1604,6 @@ async def watchdog_container(self, event: DockerContainerStateEvent) -> None:
15941604
15951605 def refresh_path_cache (self ) -> Awaitable [None ]:
15961606 """Refresh cache of existing paths."""
1597- if self .is_detached :
1607+ if self .is_detached or not self . addon_store :
15981608 return super ().refresh_path_cache ()
15991609 return self .addon_store .refresh_path_cache ()
0 commit comments