Adjust add-on installation error message (#118309)

This commit is contained in:
Stefan Agner 2024-05-29 09:41:09 +02:00 committed by GitHub
parent 98d24dd276
commit cae22e5109
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 6 deletions

View File

@ -183,13 +183,18 @@ class AddonManager:
options = {"options": config} options = {"options": config}
await async_set_addon_options(self._hass, self.addon_slug, options) await async_set_addon_options(self._hass, self.addon_slug, options)
def _check_addon_available(self, addon_info: AddonInfo) -> None:
"""Check if the managed add-on is available."""
if not addon_info.available:
raise AddonError(f"{self.addon_name} add-on is not available")
@api_error("Failed to install the {addon_name} add-on") @api_error("Failed to install the {addon_name} add-on")
async def async_install_addon(self) -> None: async def async_install_addon(self) -> None:
"""Install the managed add-on.""" """Install the managed add-on."""
addon_info = await self.async_get_addon_info() addon_info = await self.async_get_addon_info()
if not addon_info.available: self._check_addon_available(addon_info)
raise AddonError(f"{self.addon_name} add-on is not available anymore")
await async_install_addon(self._hass, self.addon_slug) await async_install_addon(self._hass, self.addon_slug)
@ -203,8 +208,7 @@ class AddonManager:
"""Update the managed add-on if needed.""" """Update the managed add-on if needed."""
addon_info = await self.async_get_addon_info() addon_info = await self.async_get_addon_info()
if not addon_info.available: self._check_addon_available(addon_info)
raise AddonError(f"{self.addon_name} add-on is not available anymore")
if addon_info.state is AddonState.NOT_INSTALLED: if addon_info.state is AddonState.NOT_INSTALLED:
raise AddonError(f"{self.addon_name} add-on is not installed") raise AddonError(f"{self.addon_name} add-on is not installed")

View File

@ -198,12 +198,12 @@ async def test_not_available_raises_exception(
with pytest.raises(AddonError) as err: with pytest.raises(AddonError) as err:
await addon_manager.async_install_addon() await addon_manager.async_install_addon()
assert str(err.value) == "Test add-on is not available anymore" assert str(err.value) == "Test add-on is not available"
with pytest.raises(AddonError) as err: with pytest.raises(AddonError) as err:
await addon_manager.async_update_addon() await addon_manager.async_update_addon()
assert str(err.value) == "Test add-on is not available anymore" assert str(err.value) == "Test add-on is not available"
async def test_get_addon_discovery_info( async def test_get_addon_discovery_info(