Docs string and exception message improvements (#1767)

This commit is contained in:
Franck Nijhof 2020-06-02 11:26:33 +02:00 committed by GitHub
parent e50515a17c
commit 9f7e0ecd55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 13 deletions

View File

@ -81,7 +81,7 @@ class Addon(AddonModel):
@property @property
def ip_address(self) -> IPv4Address: def ip_address(self) -> IPv4Address:
"""Return IP of Add-on instance.""" """Return IP of add-on instance."""
return self.instance.ip_address return self.instance.ip_address
@property @property
@ -366,7 +366,7 @@ class Addon(AddonModel):
write_json_file(self.path_options, options) write_json_file(self.path_options, options)
except vol.Invalid as ex: except vol.Invalid as ex:
_LOGGER.error( _LOGGER.error(
"Add-on %s have wrong options: %s", "Add-on %s has invalid options: %s",
self.slug, self.slug,
humanize_error(options, ex), humanize_error(options, ex),
) )
@ -524,7 +524,7 @@ class Addon(AddonModel):
Return a coroutine. Return a coroutine.
""" """
if not self.with_stdin: if not self.with_stdin:
_LOGGER.error("Add-on don't support write to stdin!") _LOGGER.error("Add-on %s does not support writing to stdin!", self.slug)
raise AddonsNotSupportedError() raise AddonsNotSupportedError()
try: try:
@ -622,7 +622,7 @@ class Addon(AddonModel):
# If available # If available
if not self._available(data[ATTR_SYSTEM]): if not self._available(data[ATTR_SYSTEM]):
_LOGGER.error("Add-on %s is not available for this Platform", self.slug) _LOGGER.error("Add-on %s is not available for this platform", self.slug)
raise AddonsNotSupportedError() raise AddonsNotSupportedError()
# Restore local add-on information # Restore local add-on information
@ -673,7 +673,9 @@ class Addon(AddonModel):
try: try:
await self.sys_host.apparmor.load_profile(self.slug, profile_file) await self.sys_host.apparmor.load_profile(self.slug, profile_file)
except HostAppArmorError: except HostAppArmorError:
_LOGGER.error("Can't restore AppArmor profile") _LOGGER.error(
"Can't restore AppArmor profile for add-on %s", self.slug
)
raise AddonsError() from None raise AddonsError() from None
# Run add-on # Run add-on

View File

@ -137,10 +137,10 @@ class APIAddons(CoreSysAttributes):
addon = self.sys_addons.get(addon_slug) addon = self.sys_addons.get(addon_slug)
if not addon: if not addon:
raise APIError("Addon does not exist") raise APIError(f"Addon {addon_slug} does not exist", addon_slug)
if check_installed and not addon.is_installed: if check_installed and not addon.is_installed:
raise APIError("Addon is not installed") raise APIError(f"Addon {addon.slug} is not installed")
return addon return addon
@ -398,7 +398,7 @@ class APIAddons(CoreSysAttributes):
"""Return icon from add-on.""" """Return icon from add-on."""
addon: AnyAddon = self._extract_addon(request, check_installed=False) addon: AnyAddon = self._extract_addon(request, check_installed=False)
if not addon.with_icon: if not addon.with_icon:
raise APIError("No icon found!") raise APIError(f"No icon found for add-on {addon.slug}!")
with addon.path_icon.open("rb") as png: with addon.path_icon.open("rb") as png:
return png.read() return png.read()
@ -408,7 +408,7 @@ class APIAddons(CoreSysAttributes):
"""Return logo from add-on.""" """Return logo from add-on."""
addon: AnyAddon = self._extract_addon(request, check_installed=False) addon: AnyAddon = self._extract_addon(request, check_installed=False)
if not addon.with_logo: if not addon.with_logo:
raise APIError("No logo found!") raise APIError(f"No logo found for add-on {addon.slug}!")
with addon.path_logo.open("rb") as png: with addon.path_logo.open("rb") as png:
return png.read() return png.read()
@ -418,7 +418,7 @@ class APIAddons(CoreSysAttributes):
"""Return changelog from add-on.""" """Return changelog from add-on."""
addon: AnyAddon = self._extract_addon(request, check_installed=False) addon: AnyAddon = self._extract_addon(request, check_installed=False)
if not addon.with_changelog: if not addon.with_changelog:
raise APIError("No changelog found!") raise APIError(f"No changelog found for add-on {addon.slug}!")
with addon.path_changelog.open("r") as changelog: with addon.path_changelog.open("r") as changelog:
return changelog.read() return changelog.read()
@ -428,7 +428,7 @@ class APIAddons(CoreSysAttributes):
"""Return documentation from add-on.""" """Return documentation from add-on."""
addon: AnyAddon = self._extract_addon(request, check_installed=False) addon: AnyAddon = self._extract_addon(request, check_installed=False)
if not addon.with_documentation: if not addon.with_documentation:
raise APIError("No documentation found!") raise APIError(f"No documentation found for add-on {addon.slug}!")
with addon.path_documentation.open("r") as documentation: with addon.path_documentation.open("r") as documentation:
return documentation.read() return documentation.read()
@ -438,7 +438,7 @@ class APIAddons(CoreSysAttributes):
"""Write to stdin of add-on.""" """Write to stdin of add-on."""
addon: AnyAddon = self._extract_addon(request) addon: AnyAddon = self._extract_addon(request)
if not addon.with_stdin: if not addon.with_stdin:
raise APIError("STDIN not supported by add-on") raise APIError(f"STDIN not supported the {addon.slug} add-on")
data = await request.read() data = await request.read()
await asyncio.shield(addon.write_stdin(data)) await asyncio.shield(addon.write_stdin(data))

View File

@ -97,7 +97,7 @@ class HassOS(CoreSysAttributes):
if cpe.get_product()[0] != "hassos": if cpe.get_product()[0] != "hassos":
raise NotImplementedError() raise NotImplementedError()
except NotImplementedError: except NotImplementedError:
_LOGGER.warning("No Home Assistant Operating-System found!") _LOGGER.warning("No Home Assistant Operating System found!")
return return
else: else:
self._available = True self._available = True