From 1b649fe5cdde5e19adaf6c2f4e47291779e879f5 Mon Sep 17 00:00:00 2001 From: Mike Degatano Date: Wed, 6 Sep 2023 12:21:04 -0400 Subject: [PATCH] Use newer StrEnum and IntEnum over Enum (#4521) * Use newer StrEnum and IntEnum over Enum * Fix validation issue and remove unnecessary .value calls --------- Co-authored-by: Pascal Vizeli --- supervisor/addons/addon.py | 2 +- supervisor/addons/const.py | 4 +- supervisor/addons/validate.py | 4 +- supervisor/api/middleware/security.py | 2 +- supervisor/config.py | 2 +- supervisor/const.py | 22 +++++------ supervisor/core.py | 2 +- supervisor/dbus/const.py | 34 ++++++++--------- supervisor/dbus/network/connection.py | 2 +- supervisor/dbus/network/setting/generate.py | 2 +- supervisor/dbus/rauc.py | 2 +- supervisor/dbus/systemd.py | 10 ++--- supervisor/dbus/udisks2/block.py | 4 +- supervisor/dbus/udisks2/const.py | 10 ++--- supervisor/dbus/udisks2/data.py | 4 +- supervisor/docker/addon.py | 38 +++++++++---------- supervisor/docker/audio.py | 6 +-- supervisor/docker/const.py | 24 ++++++------ supervisor/docker/dns.py | 2 +- supervisor/docker/homeassistant.py | 20 +++++----- supervisor/docker/multicast.py | 4 +- supervisor/docker/observer.py | 2 +- supervisor/docker/supervisor.py | 2 +- supervisor/hardware/const.py | 10 ++--- supervisor/hardware/manager.py | 2 +- supervisor/homeassistant/const.py | 6 +-- supervisor/homeassistant/core.py | 2 +- supervisor/host/const.py | 14 +++---- supervisor/host/logs.py | 2 +- supervisor/jobs/const.py | 6 +-- supervisor/jobs/decorator.py | 4 +- supervisor/mounts/const.py | 8 ++-- supervisor/mounts/mount.py | 10 ++--- supervisor/mounts/validate.py | 10 +++-- supervisor/plugins/base.py | 2 +- supervisor/resolution/checks/core_security.py | 4 +- supervisor/resolution/checks/docker_config.py | 2 +- supervisor/resolution/const.py | 12 +++--- supervisor/resolution/evaluations/base.py | 2 +- supervisor/security/const.py | 4 +- supervisor/store/const.py | 4 +- supervisor/store/validate.py | 6 +-- supervisor/supervisor.py | 2 +- supervisor/updater.py | 2 +- tests/addons/test_config.py | 4 +- tests/test_core.py | 4 +- tests/test_supervisor.py | 2 +- 47 files changed, 163 insertions(+), 165 deletions(-) diff --git a/supervisor/addons/addon.py b/supervisor/addons/addon.py index 2d722e633..8a0065d18 100644 --- a/supervisor/addons/addon.py +++ b/supervisor/addons/addon.py @@ -1000,7 +1000,7 @@ class Addon(AddonModel): _LOGGER.warning( "Watchdog found addon %s is %s, restarting...", self.name, - state.value, + state, ) try: if state == ContainerState.FAILED: diff --git a/supervisor/addons/const.py b/supervisor/addons/const.py index 06d9f8c26..5a9c892e7 100644 --- a/supervisor/addons/const.py +++ b/supervisor/addons/const.py @@ -1,11 +1,11 @@ """Add-on static data.""" from datetime import timedelta -from enum import Enum +from enum import StrEnum from ..jobs.const import JobCondition -class AddonBackupMode(str, Enum): +class AddonBackupMode(StrEnum): """Backup mode of an Add-on.""" HOT = "hot" diff --git a/supervisor/addons/validate.py b/supervisor/addons/validate.py index 341dcd050..e049f5506 100644 --- a/supervisor/addons/validate.py +++ b/supervisor/addons/validate.py @@ -212,9 +212,9 @@ def _migrate_addon_config(protocol=False): name, ) if value == "before": - config[ATTR_STARTUP] = AddonStartup.SERVICES.value + config[ATTR_STARTUP] = AddonStartup.SERVICES elif value == "after": - config[ATTR_STARTUP] = AddonStartup.APPLICATION.value + config[ATTR_STARTUP] = AddonStartup.APPLICATION # UART 2021-01-20 if "auto_uart" in config: diff --git a/supervisor/api/middleware/security.py b/supervisor/api/middleware/security.py index 255790824..fd76b6855 100644 --- a/supervisor/api/middleware/security.py +++ b/supervisor/api/middleware/security.py @@ -195,7 +195,7 @@ class SecurityMiddleware(CoreSysAttributes): CoreState.FREEZE, ): return api_return_error( - message=f"System is not ready with state: {self.sys_core.state.value}" + message=f"System is not ready with state: {self.sys_core.state}" ) return await handler(request) diff --git a/supervisor/config.py b/supervisor/config.py index ea13ea353..d861c8367 100644 --- a/supervisor/config.py +++ b/supervisor/config.py @@ -153,7 +153,7 @@ class CoreConfig(FileConfiguration): def modify_log_level(self) -> None: """Change log level.""" - lvl = getattr(logging, str(self.logging.value).upper()) + lvl = getattr(logging, self.logging.value.upper()) logging.getLogger("supervisor").setLevel(lvl) @property diff --git a/supervisor/const.py b/supervisor/const.py index 8cdbc872c..a69b18c1e 100644 --- a/supervisor/const.py +++ b/supervisor/const.py @@ -1,6 +1,6 @@ """Constants file for Supervisor.""" from dataclasses import dataclass -from enum import Enum +from enum import StrEnum from ipaddress import ip_network from pathlib import Path from sys import version_info as systemversion @@ -374,14 +374,14 @@ ROLE_ADMIN = "admin" ROLE_ALL = [ROLE_DEFAULT, ROLE_HOMEASSISTANT, ROLE_BACKUP, ROLE_MANAGER, ROLE_ADMIN] -class AddonBoot(str, Enum): +class AddonBoot(StrEnum): """Boot mode for the add-on.""" AUTO = "auto" MANUAL = "manual" -class AddonStartup(str, Enum): +class AddonStartup(StrEnum): """Startup types of Add-on.""" INITIALIZE = "initialize" @@ -391,7 +391,7 @@ class AddonStartup(str, Enum): ONCE = "once" -class AddonStage(str, Enum): +class AddonStage(StrEnum): """Stage types of add-on.""" STABLE = "stable" @@ -399,7 +399,7 @@ class AddonStage(str, Enum): DEPRECATED = "deprecated" -class AddonState(str, Enum): +class AddonState(StrEnum): """State of add-on.""" STARTUP = "startup" @@ -409,7 +409,7 @@ class AddonState(str, Enum): ERROR = "error" -class UpdateChannel(str, Enum): +class UpdateChannel(StrEnum): """Core supported update channels.""" STABLE = "stable" @@ -417,7 +417,7 @@ class UpdateChannel(str, Enum): DEV = "dev" -class CoreState(str, Enum): +class CoreState(StrEnum): """Represent current loading state.""" INITIALIZE = "initialize" @@ -430,7 +430,7 @@ class CoreState(str, Enum): CLOSE = "close" -class LogLevel(str, Enum): +class LogLevel(StrEnum): """Logging level of system.""" DEBUG = "debug" @@ -440,7 +440,7 @@ class LogLevel(str, Enum): CRITICAL = "critical" -class HostFeature(str, Enum): +class HostFeature(StrEnum): """Host feature.""" HASSOS = "hassos" @@ -452,7 +452,7 @@ class HostFeature(str, Enum): TIMEDATE = "timedate" -class BusEvent(str, Enum): +class BusEvent(StrEnum): """Bus event type.""" HARDWARE_NEW_DEVICE = "hardware_new_device" @@ -461,7 +461,7 @@ class BusEvent(str, Enum): SUPERVISOR_STATE_CHANGE = "supervisor_state_change" -class CpuArch(str, Enum): +class CpuArch(StrEnum): """Supported CPU architectures.""" ARMV7 = "armv7" diff --git a/supervisor/core.py b/supervisor/core.py index ac93ae8f2..8b41437d8 100644 --- a/supervisor/core.py +++ b/supervisor/core.py @@ -63,7 +63,7 @@ class Core(CoreSysAttributes): if self._state == new_state: return try: - RUN_SUPERVISOR_STATE.write_text(new_state.value, encoding="utf-8") + RUN_SUPERVISOR_STATE.write_text(new_state, encoding="utf-8") except OSError as err: _LOGGER.warning( "Can't update the Supervisor state to %s: %s", new_state, err diff --git a/supervisor/dbus/const.py b/supervisor/dbus/const.py index 358cb698a..012b9e953 100644 --- a/supervisor/dbus/const.py +++ b/supervisor/dbus/const.py @@ -1,5 +1,5 @@ """Constants for DBUS.""" -from enum import Enum, IntEnum +from enum import IntEnum, StrEnum from socket import AF_INET, AF_INET6 DBUS_NAME_HAOS = "io.hass.os" @@ -181,7 +181,7 @@ DBUS_ATTR_WWN = "WWN" DBUS_ERR_SYSTEMD_NO_SUCH_UNIT = "org.freedesktop.systemd1.NoSuchUnit" -class RaucState(str, Enum): +class RaucState(StrEnum): """Rauc slot states.""" GOOD = "good" @@ -189,7 +189,7 @@ class RaucState(str, Enum): ACTIVE = "active" -class InterfaceMethod(str, Enum): +class InterfaceMethod(StrEnum): """Interface method simple.""" AUTO = "auto" @@ -198,14 +198,14 @@ class InterfaceMethod(str, Enum): LINK_LOCAL = "link-local" -class ConnectionType(str, Enum): +class ConnectionType(StrEnum): """Connection type.""" ETHERNET = "802-3-ethernet" WIRELESS = "802-11-wireless" -class ConnectionStateType(int, Enum): +class ConnectionStateType(IntEnum): """Connection states. https://developer.gnome.org/NetworkManager/stable/nm-dbus-types.html#NMActiveConnectionState @@ -218,7 +218,7 @@ class ConnectionStateType(int, Enum): DEACTIVATED = 4 -class ConnectionStateFlags(int, Enum): +class ConnectionStateFlags(IntEnum): """Connection state flags. https://developer-old.gnome.org/NetworkManager/stable/nm-dbus-types.html#NMActivationStateFlags @@ -235,7 +235,7 @@ class ConnectionStateFlags(int, Enum): EXTERNAL = 0x80 -class ConnectivityState(int, Enum): +class ConnectivityState(IntEnum): """Network connectvity. https://developer.gnome.org/NetworkManager/unstable/nm-dbus-types.html#NMConnectivityState @@ -248,7 +248,7 @@ class ConnectivityState(int, Enum): CONNECTIVITY_FULL = 4 -class DeviceType(int, Enum): +class DeviceType(IntEnum): """Device types. https://developer.gnome.org/NetworkManager/stable/nm-dbus-types.html#NMDeviceType @@ -263,7 +263,7 @@ class DeviceType(int, Enum): VETH = 20 -class WirelessMethodType(int, Enum): +class WirelessMethodType(IntEnum): """Device Type.""" UNKNOWN = 0 @@ -280,7 +280,7 @@ class DNSAddressFamily(IntEnum): INET6 = AF_INET6 -class MulticastProtocolEnabled(str, Enum): +class MulticastProtocolEnabled(StrEnum): """Multicast protocol enabled or resolve.""" YES = "yes" @@ -288,7 +288,7 @@ class MulticastProtocolEnabled(str, Enum): RESOLVE = "resolve" -class DNSOverTLSEnabled(str, Enum): +class DNSOverTLSEnabled(StrEnum): """DNS over TLS enabled.""" YES = "yes" @@ -296,7 +296,7 @@ class DNSOverTLSEnabled(str, Enum): OPPORTUNISTIC = "opportunistic" -class DNSSECValidation(str, Enum): +class DNSSECValidation(StrEnum): """DNSSEC validation enforced.""" YES = "yes" @@ -304,7 +304,7 @@ class DNSSECValidation(str, Enum): ALLOW_DOWNGRADE = "allow-downgrade" -class DNSStubListenerEnabled(str, Enum): +class DNSStubListenerEnabled(StrEnum): """DNS stub listener enabled.""" YES = "yes" @@ -313,7 +313,7 @@ class DNSStubListenerEnabled(str, Enum): UDP_ONLY = "udp" -class ResolvConfMode(str, Enum): +class ResolvConfMode(StrEnum): """Resolv.conf management mode.""" FOREIGN = "foreign" @@ -323,7 +323,7 @@ class ResolvConfMode(str, Enum): UPLINK = "uplink" -class StopUnitMode(str, Enum): +class StopUnitMode(StrEnum): """Mode for stopping the unit.""" REPLACE = "replace" @@ -332,7 +332,7 @@ class StopUnitMode(str, Enum): IGNORE_REQUIREMENTS = "ignore-requirements" -class StartUnitMode(str, Enum): +class StartUnitMode(StrEnum): """Mode for starting the unit.""" REPLACE = "replace" @@ -342,7 +342,7 @@ class StartUnitMode(str, Enum): ISOLATE = "isolate" -class UnitActiveState(str, Enum): +class UnitActiveState(StrEnum): """Active state of a systemd unit.""" ACTIVE = "active" diff --git a/supervisor/dbus/network/connection.py b/supervisor/dbus/network/connection.py index fc77042bf..c43aa4001 100644 --- a/supervisor/dbus/network/connection.py +++ b/supervisor/dbus/network/connection.py @@ -121,7 +121,7 @@ class NetworkConnection(DBusInterfaceProxy): self._state_flags = { flag for flag in ConnectionStateFlags - if flag.value & self.properties[DBUS_ATTR_STATE_FLAGS] + if flag & self.properties[DBUS_ATTR_STATE_FLAGS] } or {ConnectionStateFlags.NONE} # IPv4 diff --git a/supervisor/dbus/network/setting/generate.py b/supervisor/dbus/network/setting/generate.py index 1e6316ba6..df8217756 100644 --- a/supervisor/dbus/network/setting/generate.py +++ b/supervisor/dbus/network/setting/generate.py @@ -41,7 +41,7 @@ def get_connection_from_interface( elif interface.type == InterfaceType.WIRELESS: iftype = "802-11-wireless" else: - iftype = interface.type.value + iftype = interface.type # Generate UUID if not uuid: diff --git a/supervisor/dbus/rauc.py b/supervisor/dbus/rauc.py index 44794f1d8..3c6496b90 100644 --- a/supervisor/dbus/rauc.py +++ b/supervisor/dbus/rauc.py @@ -95,7 +95,7 @@ class Rauc(DBusInterfaceProxy): @dbus_connected async def mark(self, state: RaucState, slot_identifier: str) -> tuple[str, str]: """Get slot status.""" - return await self.dbus.Installer.call_mark(state.value, slot_identifier) + return await self.dbus.Installer.call_mark(state, slot_identifier) @dbus_connected async def update(self, changed: dict[str, Any] | None = None) -> None: diff --git a/supervisor/dbus/systemd.py b/supervisor/dbus/systemd.py index 4ae5903a7..b1bb0341b 100644 --- a/supervisor/dbus/systemd.py +++ b/supervisor/dbus/systemd.py @@ -122,25 +122,25 @@ class Systemd(DBusInterfaceProxy): @systemd_errors async def start_unit(self, unit: str, mode: StartUnitMode) -> str: """Start a systemd service unit. Returns object path of job.""" - return await self.dbus.Manager.call_start_unit(unit, mode.value) + return await self.dbus.Manager.call_start_unit(unit, mode) @dbus_connected @systemd_errors async def stop_unit(self, unit: str, mode: StopUnitMode) -> str: """Stop a systemd service unit. Returns object path of job.""" - return await self.dbus.Manager.call_stop_unit(unit, mode.value) + return await self.dbus.Manager.call_stop_unit(unit, mode) @dbus_connected @systemd_errors async def reload_unit(self, unit: str, mode: StartUnitMode) -> str: """Reload a systemd service unit. Returns object path of job.""" - return await self.dbus.Manager.call_reload_or_restart_unit(unit, mode.value) + return await self.dbus.Manager.call_reload_or_restart_unit(unit, mode) @dbus_connected @systemd_errors async def restart_unit(self, unit: str, mode: StartUnitMode) -> str: """Restart a systemd service unit. Returns object path of job.""" - return await self.dbus.Manager.call_restart_unit(unit, mode.value) + return await self.dbus.Manager.call_restart_unit(unit, mode) @dbus_connected async def list_units( @@ -155,7 +155,7 @@ class Systemd(DBusInterfaceProxy): ) -> str: """Start a transient unit which is released when stopped or on reboot. Returns object path of job.""" return await self.dbus.Manager.call_start_transient_unit( - unit, mode.value, properties, [] + unit, mode, properties, [] ) @dbus_connected diff --git a/supervisor/dbus/udisks2/block.py b/supervisor/dbus/udisks2/block.py index e0d662240..c8d710248 100644 --- a/supervisor/dbus/udisks2/block.py +++ b/supervisor/dbus/udisks2/block.py @@ -263,6 +263,4 @@ class UDisks2Block(DBusInterfaceProxy): ) -> None: """Format block device.""" options = options.to_dict() if options else {} - await self.dbus.Block.call_format( - type_.value, options | UDISKS2_DEFAULT_OPTIONS - ) + await self.dbus.Block.call_format(type_, options | UDISKS2_DEFAULT_OPTIONS) diff --git a/supervisor/dbus/udisks2/const.py b/supervisor/dbus/udisks2/const.py index 2afce1f6f..d45314941 100644 --- a/supervisor/dbus/udisks2/const.py +++ b/supervisor/dbus/udisks2/const.py @@ -1,20 +1,20 @@ """Constants for UDisks2.""" -from enum import Enum +from enum import StrEnum from dbus_fast import Variant UDISKS2_DEFAULT_OPTIONS = {"auth.no_user_interaction": Variant("b", True)} -class EncryptType(str, Enum): +class EncryptType(StrEnum): """Encryption type.""" LUKS1 = "luks1" LUKS2 = "luks2" -class EraseMode(str, Enum): +class EraseMode(StrEnum): """Erase mode.""" ZERO = "zero" @@ -22,7 +22,7 @@ class EraseMode(str, Enum): ATA_SECURE_ERASE_ENHANCED = "ata-secure-erase-enhanced" -class FormatType(str, Enum): +class FormatType(StrEnum): """Format type.""" EMPTY = "empty" @@ -31,7 +31,7 @@ class FormatType(str, Enum): GPT = "gpt" -class PartitionTableType(str, Enum): +class PartitionTableType(StrEnum): """Partition Table type.""" DOS = "dos" diff --git a/supervisor/dbus/udisks2/data.py b/supervisor/dbus/udisks2/data.py index 566f37762..0305295c2 100644 --- a/supervisor/dbus/udisks2/data.py +++ b/supervisor/dbus/udisks2/data.py @@ -167,10 +167,10 @@ class FormatOptions(UDisks2StandardOptions): ) if self.encrypt_passpharase else None, - "encrypt.type": Variant("s", self.encrypt_type.value) + "encrypt.type": Variant("s", self.encrypt_type) if self.encrypt_type else None, - "erase": Variant("s", self.erase.value) if self.erase else None, + "erase": Variant("s", self.erase) if self.erase else None, "update-partition-type": _optional_variant("b", self.update_partition_type), "no-block": _optional_variant("b", self.no_block), "dry-run-first": _optional_variant("b", self.dry_run_first), diff --git a/supervisor/docker/addon.py b/supervisor/docker/addon.py index 717a8fe0a..05da47c44 100644 --- a/supervisor/docker/addon.py +++ b/supervisor/docker/addon.py @@ -278,7 +278,7 @@ class DockerAddon(DockerInterface): return None @property - def capabilities(self) -> list[str] | None: + def capabilities(self) -> list[Capabilities] | None: """Generate needed capabilities.""" capabilities: set[Capabilities] = set(self.addon.privileged) @@ -292,7 +292,7 @@ class DockerAddon(DockerInterface): # Return None if no capabilities is present if capabilities: - return [cap.value for cap in capabilities] + return list(capabilities) return None @property @@ -332,7 +332,7 @@ class DockerAddon(DockerInterface): mounts = [ MOUNT_DEV, Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.addon.path_extern_data.as_posix(), target="/data", read_only=False, @@ -343,7 +343,7 @@ class DockerAddon(DockerInterface): if MAP_CONFIG in addon_mapping: mounts.append( Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_config.path_extern_homeassistant.as_posix(), target="/config", read_only=addon_mapping[MAP_CONFIG], @@ -353,7 +353,7 @@ class DockerAddon(DockerInterface): if MAP_SSL in addon_mapping: mounts.append( Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_config.path_extern_ssl.as_posix(), target="/ssl", read_only=addon_mapping[MAP_SSL], @@ -363,7 +363,7 @@ class DockerAddon(DockerInterface): if MAP_ADDONS in addon_mapping: mounts.append( Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_config.path_extern_addons_local.as_posix(), target="/addons", read_only=addon_mapping[MAP_ADDONS], @@ -373,7 +373,7 @@ class DockerAddon(DockerInterface): if MAP_BACKUP in addon_mapping: mounts.append( Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_config.path_extern_backup.as_posix(), target="/backup", read_only=addon_mapping[MAP_BACKUP], @@ -383,22 +383,22 @@ class DockerAddon(DockerInterface): if MAP_SHARE in addon_mapping: mounts.append( Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_config.path_extern_share.as_posix(), target="/share", read_only=addon_mapping[MAP_SHARE], - propagation=PropagationMode.RSLAVE.value, + propagation=PropagationMode.RSLAVE, ) ) if MAP_MEDIA in addon_mapping: mounts.append( Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_config.path_extern_media.as_posix(), target="/media", read_only=addon_mapping[MAP_MEDIA], - propagation=PropagationMode.RSLAVE.value, + propagation=PropagationMode.RSLAVE, ) ) @@ -411,7 +411,7 @@ class DockerAddon(DockerInterface): continue mounts.append( Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=gpio_path, target=gpio_path, read_only=False, @@ -422,7 +422,7 @@ class DockerAddon(DockerInterface): if self.addon.with_devicetree: mounts.append( Mount( - type=MountType.BIND.value, + type=MountType.BIND, source="/sys/firmware/devicetree/base", target="/device-tree", read_only=True, @@ -437,7 +437,7 @@ class DockerAddon(DockerInterface): if self.addon.with_kernel_modules: mounts.append( Mount( - type=MountType.BIND.value, + type=MountType.BIND, source="/lib/modules", target="/lib/modules", read_only=True, @@ -456,19 +456,19 @@ class DockerAddon(DockerInterface): if self.addon.with_audio: mounts += [ Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.addon.path_extern_pulse.as_posix(), target="/etc/pulse/client.conf", read_only=True, ), Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_plugins.audio.path_extern_pulse.as_posix(), target="/run/audio", read_only=True, ), Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_plugins.audio.path_extern_asound.as_posix(), target="/etc/asound.conf", read_only=True, @@ -479,13 +479,13 @@ class DockerAddon(DockerInterface): if self.addon.with_journald: mounts += [ Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=SYSTEMD_JOURNAL_PERSISTENT.as_posix(), target=SYSTEMD_JOURNAL_PERSISTENT.as_posix(), read_only=True, ), Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=SYSTEMD_JOURNAL_VOLATILE.as_posix(), target=SYSTEMD_JOURNAL_VOLATILE.as_posix(), read_only=True, diff --git a/supervisor/docker/audio.py b/supervisor/docker/audio.py index f9c58ed17..eeb34249d 100644 --- a/supervisor/docker/audio.py +++ b/supervisor/docker/audio.py @@ -45,7 +45,7 @@ class DockerAudio(DockerInterface, CoreSysAttributes): mounts = [ MOUNT_DEV, Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_config.path_extern_audio.as_posix(), target="/data", read_only=False, @@ -68,9 +68,9 @@ class DockerAudio(DockerInterface, CoreSysAttributes): ) + self.sys_hardware.policy.get_cgroups_rules(PolicyGroup.BLUETOOTH) @property - def capabilities(self) -> list[str]: + def capabilities(self) -> list[Capabilities]: """Generate needed capabilities.""" - return [cap.value for cap in (Capabilities.SYS_NICE, Capabilities.SYS_RESOURCE)] + return [Capabilities.SYS_NICE, Capabilities.SYS_RESOURCE] @property def ulimits(self) -> list[docker.types.Ulimit]: diff --git a/supervisor/docker/const.py b/supervisor/docker/const.py index f8e3edbeb..2a9740586 100644 --- a/supervisor/docker/const.py +++ b/supervisor/docker/const.py @@ -1,12 +1,12 @@ """Docker constants.""" -from enum import Enum +from enum import StrEnum from docker.types import Mount from ..const import MACHINE_ID -class Capabilities(str, Enum): +class Capabilities(StrEnum): """Linux Capabilities.""" BPF = "BPF" @@ -24,7 +24,7 @@ class Capabilities(str, Enum): SYS_TIME = "SYS_TIME" -class ContainerState(str, Enum): +class ContainerState(StrEnum): """State of supervisor managed docker container.""" FAILED = "failed" @@ -35,7 +35,7 @@ class ContainerState(str, Enum): UNKNOWN = "unknown" -class RestartPolicy(str, Enum): +class RestartPolicy(StrEnum): """Restart policy of container.""" NO = "no" @@ -44,7 +44,7 @@ class RestartPolicy(str, Enum): ALWAYS = "always" -class MountType(str, Enum): +class MountType(StrEnum): """Mount type.""" BIND = "bind" @@ -53,7 +53,7 @@ class MountType(str, Enum): NPIPE = "npipe" -class PropagationMode(str, Enum): +class PropagationMode(StrEnum): """Propagataion mode, only for bind type mounts.""" PRIVATE = "private" @@ -71,23 +71,21 @@ ENV_TOKEN_OLD = "HASSIO_TOKEN" LABEL_MANAGED = "supervisor_managed" MOUNT_DBUS = Mount( - type=MountType.BIND.value, source="/run/dbus", target="/run/dbus", read_only=True -) -MOUNT_DEV = Mount( - type=MountType.BIND.value, source="/dev", target="/dev", read_only=True + type=MountType.BIND, source="/run/dbus", target="/run/dbus", read_only=True ) +MOUNT_DEV = Mount(type=MountType.BIND, source="/dev", target="/dev", read_only=True) MOUNT_DOCKER = Mount( - type=MountType.BIND.value, + type=MountType.BIND, source="/run/docker.sock", target="/run/docker.sock", read_only=True, ) MOUNT_MACHINE_ID = Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=MACHINE_ID.as_posix(), target=MACHINE_ID.as_posix(), read_only=True, ) MOUNT_UDEV = Mount( - type=MountType.BIND.value, source="/run/udev", target="/run/udev", read_only=True + type=MountType.BIND, source="/run/udev", target="/run/udev", read_only=True ) diff --git a/supervisor/docker/dns.py b/supervisor/docker/dns.py index e4e620e8a..56fd07082 100644 --- a/supervisor/docker/dns.py +++ b/supervisor/docker/dns.py @@ -56,7 +56,7 @@ class DockerDNS(DockerInterface, CoreSysAttributes): environment={ENV_TIME: self.sys_timezone}, mounts=[ Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_config.path_extern_dns.as_posix(), target="/config", read_only=False, diff --git a/supervisor/docker/homeassistant.py b/supervisor/docker/homeassistant.py index 2f8cafc57..c96f6c760 100644 --- a/supervisor/docker/homeassistant.py +++ b/supervisor/docker/homeassistant.py @@ -85,7 +85,7 @@ class DockerHomeAssistant(DockerInterface): MOUNT_UDEV, # HA config folder Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_config.path_extern_homeassistant.as_posix(), target="/config", read_only=False, @@ -98,20 +98,20 @@ class DockerHomeAssistant(DockerInterface): [ # All other folders Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_config.path_extern_ssl.as_posix(), target="/ssl", read_only=True, ), Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_config.path_extern_share.as_posix(), target="/share", read_only=False, propagation=PropagationMode.RSLAVE.value, ), Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_config.path_extern_media.as_posix(), target="/media", read_only=False, @@ -119,19 +119,19 @@ class DockerHomeAssistant(DockerInterface): ), # Configuration audio Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_homeassistant.path_extern_pulse.as_posix(), target="/etc/pulse/client.conf", read_only=True, ), Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_plugins.audio.path_extern_pulse.as_posix(), target="/run/audio", read_only=True, ), Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_plugins.audio.path_extern_asound.as_posix(), target="/etc/asound.conf", read_only=True, @@ -212,19 +212,19 @@ class DockerHomeAssistant(DockerInterface): stderr=True, mounts=[ Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_config.path_extern_homeassistant.as_posix(), target="/config", read_only=False, ), Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_config.path_extern_ssl.as_posix(), target="/ssl", read_only=True, ), Mount( - type=MountType.BIND.value, + type=MountType.BIND, source=self.sys_config.path_extern_share.as_posix(), target="/share", read_only=False, diff --git a/supervisor/docker/multicast.py b/supervisor/docker/multicast.py index d24686c12..4c8947f88 100644 --- a/supervisor/docker/multicast.py +++ b/supervisor/docker/multicast.py @@ -27,9 +27,9 @@ class DockerMulticast(DockerInterface, CoreSysAttributes): return MULTICAST_DOCKER_NAME @property - def capabilities(self) -> list[str]: + def capabilities(self) -> list[Capabilities]: """Generate needed capabilities.""" - return [Capabilities.NET_ADMIN.value] + return [Capabilities.NET_ADMIN] @Job( name="docker_multicast_run", diff --git a/supervisor/docker/observer.py b/supervisor/docker/observer.py index a1d5c66c6..1f0eeaa3c 100644 --- a/supervisor/docker/observer.py +++ b/supervisor/docker/observer.py @@ -52,7 +52,7 @@ class DockerObserver(DockerInterface, CoreSysAttributes): hostname=self.name.replace("_", "-"), detach=True, security_opt=self.security_opt, - restart_policy={"Name": RestartPolicy.ALWAYS.value}, + restart_policy={"Name": RestartPolicy.ALWAYS}, extra_hosts={"supervisor": self.sys_docker.network.supervisor}, environment={ ENV_TIME: self.sys_timezone, diff --git a/supervisor/docker/supervisor.py b/supervisor/docker/supervisor.py index e78c87744..b347f73d8 100644 --- a/supervisor/docker/supervisor.py +++ b/supervisor/docker/supervisor.py @@ -39,7 +39,7 @@ class DockerSupervisor(DockerInterface): def host_mounts_available(self) -> bool: """Return True if container can see mounts on host within its data directory.""" return self._meta and any( - mount.get("Propagation") == PropagationMode.SLAVE.value + mount.get("Propagation") == PropagationMode.SLAVE for mount in self.meta_mounts if mount.get("Destination") == "/data" ) diff --git a/supervisor/hardware/const.py b/supervisor/hardware/const.py index 8975657b2..8dd72db4b 100644 --- a/supervisor/hardware/const.py +++ b/supervisor/hardware/const.py @@ -1,8 +1,8 @@ """Constants for hardware.""" -from enum import Enum +from enum import StrEnum -class UdevSubsystem(str, Enum): +class UdevSubsystem(StrEnum): """Udev subsystem class.""" SERIAL = "tty" @@ -24,7 +24,7 @@ class UdevSubsystem(str, Enum): RPI_H264MEM = "rpivid-h264mem" -class PolicyGroup(str, Enum): +class PolicyGroup(StrEnum): """Policy groups backend.""" UART = "uart" @@ -35,14 +35,14 @@ class PolicyGroup(str, Enum): BLUETOOTH = "bluetooth" -class HardwareAction(str, Enum): +class HardwareAction(StrEnum): """Hardware device action.""" ADD = "add" REMOVE = "remove" -class UdevKernelAction(str, Enum): +class UdevKernelAction(StrEnum): """Udev kernel device action.""" ADD = "add" diff --git a/supervisor/hardware/manager.py b/supervisor/hardware/manager.py index 6af0481a7..30dc44b6f 100644 --- a/supervisor/hardware/manager.py +++ b/supervisor/hardware/manager.py @@ -94,7 +94,7 @@ class HardwareManager(CoreSysAttributes): udev_device: pyudev.Device = pyudev.Devices.from_sys_path( self._udev, str(device.sysfs) ) - return udev_device.find_parent(subsystem.value) is not None + return udev_device.find_parent(subsystem) is not None def _import_devices(self) -> None: """Import fresh from udev database.""" diff --git a/supervisor/homeassistant/const.py b/supervisor/homeassistant/const.py index 826eca3ed..cecfe6761 100644 --- a/supervisor/homeassistant/const.py +++ b/supervisor/homeassistant/const.py @@ -1,6 +1,6 @@ """Constants for homeassistant.""" from datetime import timedelta -from enum import Enum +from enum import StrEnum from awesomeversion import AwesomeVersion @@ -19,7 +19,7 @@ CLOSING_STATES = [ ] -class WSType(str, Enum): +class WSType(StrEnum): """Websocket types.""" AUTH = "auth" @@ -28,7 +28,7 @@ class WSType(str, Enum): BACKUP_END = "backup/end" -class WSEvent(str, Enum): +class WSEvent(StrEnum): """Websocket events.""" ADDON = "addon" diff --git a/supervisor/homeassistant/core.py b/supervisor/homeassistant/core.py index 55e799ac9..71d9d5342 100644 --- a/supervisor/homeassistant/core.py +++ b/supervisor/homeassistant/core.py @@ -492,7 +492,7 @@ class HomeAssistantCore(JobGroup): # Don't interrupt a task in progress or if rollback is handling it if not (self.in_progress or self.error_state): _LOGGER.warning( - "Watchdog found Home Assistant %s, restarting...", state.value + "Watchdog found Home Assistant %s, restarting...", state ) if state == ContainerState.FAILED and attempts == 0: try: diff --git a/supervisor/host/const.py b/supervisor/host/const.py index 34bdae6c0..42931cc12 100644 --- a/supervisor/host/const.py +++ b/supervisor/host/const.py @@ -1,12 +1,12 @@ """Const for host.""" -from enum import Enum +from enum import StrEnum PARAM_BOOT_ID = "_BOOT_ID" PARAM_FOLLOW = "follow" PARAM_SYSLOG_IDENTIFIER = "SYSLOG_IDENTIFIER" -class InterfaceMethod(str, Enum): +class InterfaceMethod(StrEnum): """Configuration of an interface.""" DISABLED = "disabled" @@ -14,7 +14,7 @@ class InterfaceMethod(str, Enum): AUTO = "auto" -class InterfaceType(str, Enum): +class InterfaceType(StrEnum): """Configuration of an interface.""" ETHERNET = "ethernet" @@ -22,7 +22,7 @@ class InterfaceType(str, Enum): VLAN = "vlan" -class AuthMethod(str, Enum): +class AuthMethod(StrEnum): """Authentication method.""" OPEN = "open" @@ -30,7 +30,7 @@ class AuthMethod(str, Enum): WPA_PSK = "wpa-psk" -class WifiMode(str, Enum): +class WifiMode(StrEnum): """Wifi mode.""" INFRASTRUCTURE = "infrastructure" @@ -39,7 +39,7 @@ class WifiMode(str, Enum): AP = "ap" -class HostFeature(str, Enum): +class HostFeature(StrEnum): """Host feature.""" DISK = "disk" @@ -56,7 +56,7 @@ class HostFeature(str, Enum): TIMEDATE = "timedate" -class LogFormat(str, Enum): +class LogFormat(StrEnum): """Log format.""" JOURNAL = "application/vnd.fdo.journal" diff --git a/supervisor/host/logs.py b/supervisor/host/logs.py index d03cdab79..7df3d58d3 100644 --- a/supervisor/host/logs.py +++ b/supervisor/host/logs.py @@ -142,7 +142,7 @@ class LogsControl(CoreSysAttributes): async with ClientSession( connector=UnixConnector(path="/run/systemd-journal-gatewayd.sock") ) as session: - headers = {ACCEPT: accept.value} + headers = {ACCEPT: accept} if range_header: headers[RANGE] = range_header async with session.get( diff --git a/supervisor/jobs/const.py b/supervisor/jobs/const.py index 5ef27ba95..3b1ea0e8b 100644 --- a/supervisor/jobs/const.py +++ b/supervisor/jobs/const.py @@ -1,5 +1,5 @@ """Jobs constants.""" -from enum import Enum +from enum import StrEnum from pathlib import Path from ..const import SUPERVISOR_DATA @@ -13,7 +13,7 @@ JOB_GROUP_DOCKER_INTERFACE = "container_{name}" JOB_GROUP_HOME_ASSISTANT_CORE = "home_assistant_core" -class JobCondition(str, Enum): +class JobCondition(StrEnum): """Job condition enum.""" AUTO_UPDATE = "auto_update" @@ -30,7 +30,7 @@ class JobCondition(str, Enum): SUPERVISOR_UPDATED = "supervisor_updated" -class JobExecutionLimit(str, Enum): +class JobExecutionLimit(StrEnum): """Job Execution limits.""" ONCE = "once" diff --git a/supervisor/jobs/decorator.py b/supervisor/jobs/decorator.py index 1ca28770c..3999c6015 100644 --- a/supervisor/jobs/decorator.py +++ b/supervisor/jobs/decorator.py @@ -72,7 +72,7 @@ class Job(CoreSysAttributes): and self._throttle_period is None ): raise RuntimeError( - f"Job {name} is using execution limit {limit.value} without a throttle period!" + f"Job {name} is using execution limit {limit} without a throttle period!" ) if self.limit in ( @@ -81,7 +81,7 @@ class Job(CoreSysAttributes): ): if self.throttle_max_calls is None: raise RuntimeError( - f"Job {name} is using execution limit {limit.value} without throttle max calls!" + f"Job {name} is using execution limit {limit} without throttle max calls!" ) self._rate_limited_calls = {} diff --git a/supervisor/mounts/const.py b/supervisor/mounts/const.py index a3302c9cc..36c27b014 100644 --- a/supervisor/mounts/const.py +++ b/supervisor/mounts/const.py @@ -1,6 +1,6 @@ """Constants for mount manager.""" -from enum import Enum +from enum import StrEnum from pathlib import PurePath FILE_CONFIG_MOUNTS = PurePath("mounts.json") @@ -13,7 +13,7 @@ ATTR_SHARE = "share" ATTR_USAGE = "usage" -class MountType(str, Enum): +class MountType(StrEnum): """Mount type.""" BIND = "bind" @@ -21,7 +21,7 @@ class MountType(str, Enum): NFS = "nfs" -class MountUsage(str, Enum): +class MountUsage(StrEnum): """Mount usage.""" BACKUP = "backup" @@ -29,7 +29,7 @@ class MountUsage(str, Enum): SHARE = "share" -class MountCifsVersion(str, Enum): +class MountCifsVersion(StrEnum): """Mount CIFS version.""" LEGACY_1_0 = "1.0" diff --git a/supervisor/mounts/mount.py b/supervisor/mounts/mount.py index a76eab683..ee5a56fb6 100644 --- a/supervisor/mounts/mount.py +++ b/supervisor/mounts/mount.py @@ -81,7 +81,7 @@ class Mount(CoreSysAttributes, ABC): def to_dict(self, *, skip_secrets: bool = True) -> MountData: """Return dictionary representation.""" - return MountData(name=self.name, type=self.type.value, usage=self.usage.value) + return MountData(name=self.name, type=self.type, usage=self.usage) @property def name(self) -> str: @@ -120,7 +120,7 @@ class Mount(CoreSysAttributes, ABC): @property def description(self) -> str: """Description of mount.""" - return f"Supervisor {self.type.value} mount: {self.name}" + return f"Supervisor {self.type} mount: {self.name}" @property def unit_name(self) -> str: @@ -240,7 +240,7 @@ class Mount(CoreSysAttributes, ABC): else [] ) if self.type != MountType.BIND: - options += [(DBUS_ATTR_TYPE, Variant("s", self.type.value))] + options += [(DBUS_ATTR_TYPE, Variant("s", self.type))] await self.sys_dbus.systemd.start_transient_unit( self.unit_name, @@ -467,9 +467,9 @@ class BindMount(Mount): coresys, MountData( name=name, - type=MountType.BIND.value, + type=MountType.BIND, path=path.as_posix(), - usage=usage and usage.value, + usage=usage and usage, ), where=where, ) diff --git a/supervisor/mounts/validate.py b/supervisor/mounts/validate.py index 71db224b9..b64e7f261 100644 --- a/supervisor/mounts/validate.py +++ b/supervisor/mounts/validate.py @@ -38,8 +38,10 @@ VALIDATE_SHARE = vol.Match(RE_PATH_PART) _SCHEMA_BASE_MOUNT_CONFIG = vol.Schema( { vol.Required(ATTR_NAME): VALIDATE_NAME, - vol.Required(ATTR_TYPE): vol.In([MountType.CIFS.value, MountType.NFS.value]), - vol.Required(ATTR_USAGE): vol.In([u.value for u in MountUsage]), + vol.Required(ATTR_TYPE): vol.All( + vol.In([MountType.CIFS.value, MountType.NFS.value]), vol.Coerce(MountType) + ), + vol.Required(ATTR_USAGE): vol.Coerce(MountUsage), }, extra=vol.REMOVE_EXTRA, ) @@ -53,7 +55,7 @@ _SCHEMA_MOUNT_NETWORK = _SCHEMA_BASE_MOUNT_CONFIG.extend( SCHEMA_MOUNT_CIFS = _SCHEMA_MOUNT_NETWORK.extend( { - vol.Required(ATTR_TYPE): MountType.CIFS.value, + vol.Required(ATTR_TYPE): vol.All(MountType.CIFS.value, vol.Coerce(MountType)), vol.Required(ATTR_SHARE): VALIDATE_SHARE, vol.Inclusive(ATTR_USERNAME, "basic_auth"): str, vol.Inclusive(ATTR_PASSWORD, "basic_auth"): str, @@ -65,7 +67,7 @@ SCHEMA_MOUNT_CIFS = _SCHEMA_MOUNT_NETWORK.extend( SCHEMA_MOUNT_NFS = _SCHEMA_MOUNT_NETWORK.extend( { - vol.Required(ATTR_TYPE): MountType.NFS.value, + vol.Required(ATTR_TYPE): vol.All(MountType.NFS.value, vol.Coerce(MountType)), vol.Required(ATTR_PATH): str, } ) diff --git a/supervisor/plugins/base.py b/supervisor/plugins/base.py index 7237974df..a32805f8d 100644 --- a/supervisor/plugins/base.py +++ b/supervisor/plugins/base.py @@ -120,7 +120,7 @@ class PluginBase(ABC, FileConfiguration, CoreSysAttributes): _LOGGER.warning( "Watchdog found %s plugin %s, restarting...", self.slug, - state.value, + state, ) try: if state == ContainerState.STOPPED and attempts == 0: diff --git a/supervisor/resolution/checks/core_security.py b/supervisor/resolution/checks/core_security.py index 99e5548e0..7922f38ee 100644 --- a/supervisor/resolution/checks/core_security.py +++ b/supervisor/resolution/checks/core_security.py @@ -1,5 +1,5 @@ """Helpers to check core security.""" -from enum import Enum +from enum import StrEnum from pathlib import Path from awesomeversion import AwesomeVersion, AwesomeVersionException @@ -15,7 +15,7 @@ def setup(coresys: CoreSys) -> CheckBase: return CheckCoreSecurity(coresys) -class SecurityReference(str, Enum): +class SecurityReference(StrEnum): """Version references.""" CUSTOM_COMPONENTS_BELOW_2021_1_5 = "custom_components_below_2021_1_5" diff --git a/supervisor/resolution/checks/docker_config.py b/supervisor/resolution/checks/docker_config.py index 71cde6008..adb36154a 100644 --- a/supervisor/resolution/checks/docker_config.py +++ b/supervisor/resolution/checks/docker_config.py @@ -12,7 +12,7 @@ from .base import CheckBase def _check_container(container: DockerInterface) -> bool: """Return true if container has a config issue.""" return any( - mount.get("Propagation") != PropagationMode.RSLAVE.value + mount.get("Propagation") != PropagationMode.RSLAVE for mount in container.meta_mounts if mount.get("Destination") in ["/media", "/share"] ) diff --git a/supervisor/resolution/const.py b/supervisor/resolution/const.py index 6c80cf836..232935877 100644 --- a/supervisor/resolution/const.py +++ b/supervisor/resolution/const.py @@ -1,5 +1,5 @@ """Constants for the resoulution manager.""" -from enum import Enum +from enum import StrEnum from pathlib import Path from ..const import SUPERVISOR_DATA @@ -15,7 +15,7 @@ DNS_CHECK_HOST = "_checkdns.home-assistant.io" DNS_ERROR_NO_DATA = 1 -class ContextType(str, Enum): +class ContextType(StrEnum): """Place where somethings was happening.""" ADDON = "addon" @@ -29,7 +29,7 @@ class ContextType(str, Enum): SYSTEM = "system" -class UnsupportedReason(str, Enum): +class UnsupportedReason(StrEnum): """Reasons for unsupported status.""" APPARMOR = "apparmor" @@ -55,7 +55,7 @@ class UnsupportedReason(str, Enum): SYSTEMD_RESOLVED = "systemd_resolved" -class UnhealthyReason(str, Enum): +class UnhealthyReason(StrEnum): """Reasons for unsupported status.""" DOCKER = "docker" @@ -65,7 +65,7 @@ class UnhealthyReason(str, Enum): UNTRUSTED = "untrusted" -class IssueType(str, Enum): +class IssueType(StrEnum): """Issue type.""" CORRUPT_DOCKER = "corrupt_docker" @@ -91,7 +91,7 @@ class IssueType(str, Enum): UPDATE_ROLLBACK = "update_rollback" -class SuggestionType(str, Enum): +class SuggestionType(StrEnum): """Sugestion type.""" CLEAR_FULL_BACKUP = "clear_full_backup" diff --git a/supervisor/resolution/evaluations/base.py b/supervisor/resolution/evaluations/base.py index 5ebfe8c8b..933263866 100644 --- a/supervisor/resolution/evaluations/base.py +++ b/supervisor/resolution/evaluations/base.py @@ -26,7 +26,7 @@ class EvaluateBase(ABC, CoreSysAttributes): _LOGGER.warning( "%s (more-info: https://www.home-assistant.io/more-info/unsupported/%s)", self.on_failure, - self.reason.value, + self.reason, ) else: if self.reason in self.sys_resolution.unsupported: diff --git a/supervisor/security/const.py b/supervisor/security/const.py index 40306ac68..ee6d0a835 100644 --- a/supervisor/security/const.py +++ b/supervisor/security/const.py @@ -1,10 +1,10 @@ """Security constants.""" -from enum import Enum +from enum import StrEnum import attr -class ContentTrustResult(str, Enum): +class ContentTrustResult(StrEnum): """Content trust result enum.""" PASS = "pass" diff --git a/supervisor/store/const.py b/supervisor/store/const.py index a0b2cd52a..81429236f 100644 --- a/supervisor/store/const.py +++ b/supervisor/store/const.py @@ -1,5 +1,5 @@ """Constants for the add-on store.""" -from enum import Enum +from enum import StrEnum from pathlib import Path from ..const import SUPERVISOR_DATA @@ -7,7 +7,7 @@ from ..const import SUPERVISOR_DATA FILE_HASSIO_STORE = Path(SUPERVISOR_DATA, "store.json") -class StoreType(str, Enum): +class StoreType(StrEnum): """Store Types.""" CORE = "core" diff --git a/supervisor/store/validate.py b/supervisor/store/validate.py index af53e8535..0106c72aa 100644 --- a/supervisor/store/validate.py +++ b/supervisor/store/validate.py @@ -9,8 +9,8 @@ from .const import StoreType URL_COMMUNITY_ADDONS = "https://github.com/hassio-addons/repository" URL_ESPHOME = "https://github.com/esphome/home-assistant-addon" BUILTIN_REPOSITORIES = { - StoreType.CORE.value, - StoreType.LOCAL.value, + StoreType.CORE, + StoreType.LOCAL, URL_COMMUNITY_ADDONS, URL_ESPHOME, } @@ -28,7 +28,7 @@ SCHEMA_REPOSITORY_CONFIG = vol.Schema( def validate_repository(repository: str) -> str: """Validate a valid repository.""" - if repository in [StoreType.CORE.value, StoreType.LOCAL.value]: + if repository in [StoreType.CORE, StoreType.LOCAL]: return repository data = RE_REPOSITORY.match(repository) diff --git a/supervisor/supervisor.py b/supervisor/supervisor.py index 56fe9668f..18619cca1 100644 --- a/supervisor/supervisor.py +++ b/supervisor/supervisor.py @@ -115,7 +115,7 @@ class Supervisor(CoreSysAttributes): async def update_apparmor(self) -> None: """Fetch last version and update profile.""" - url = URL_HASSIO_APPARMOR.format(channel=self.sys_updater.channel.value) + url = URL_HASSIO_APPARMOR.format(channel=self.sys_updater.channel) # Fetch try: diff --git a/supervisor/updater.py b/supervisor/updater.py index e32f8d895..cee2b6b8a 100644 --- a/supervisor/updater.py +++ b/supervisor/updater.py @@ -192,7 +192,7 @@ class Updater(FileConfiguration, CoreSysAttributes): Is a coroutine. """ - url = URL_HASSIO_VERSION.format(channel=self.channel.value) + url = URL_HASSIO_VERSION.format(channel=self.channel) machine = self.sys_machine or "default" # Get data diff --git a/tests/addons/test_config.py b/tests/addons/test_config.py index 24dde598b..e35d6cbbf 100644 --- a/tests/addons/test_config.py +++ b/tests/addons/test_config.py @@ -41,13 +41,13 @@ def test_migration_startup(): valid_config = vd.SCHEMA_ADDON_CONFIG(config) - assert valid_config["startup"].value == "services" + assert valid_config["startup"] == "services" config["startup"] = "after" valid_config = vd.SCHEMA_ADDON_CONFIG(config) - assert valid_config["startup"].value == "application" + assert valid_config["startup"] == "application" def test_migration_auto_uart(): diff --git a/tests/test_core.py b/tests/test_core.py index 8e25bac68..eaf559579 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -9,8 +9,8 @@ def test_write_state(run_dir, coresys: CoreSys): coresys.core.state = CoreState.RUNNING - assert run_dir.read_text() == CoreState.RUNNING.value + assert run_dir.read_text() == CoreState.RUNNING coresys.core.state = CoreState.SHUTDOWN - assert run_dir.read_text() == CoreState.SHUTDOWN.value + assert run_dir.read_text() == CoreState.SHUTDOWN diff --git a/tests/test_supervisor.py b/tests/test_supervisor.py index 68d8017e8..c9a516a85 100644 --- a/tests/test_supervisor.py +++ b/tests/test_supervisor.py @@ -104,7 +104,7 @@ async def test_update_apparmor( await coresys.supervisor.update_apparmor() get.assert_called_once_with( - f"https://version.home-assistant.io/apparmor_{channel.value}.txt", + f"https://version.home-assistant.io/apparmor_{channel}.txt", timeout=ClientTimeout(total=10), ) load_profile.assert_called_once()