From 7a5a01bdcc6c715970f3f33fdd33a9525bf4e30b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Wed, 26 Aug 2020 14:11:21 +0200 Subject: [PATCH] Add network to host suppported features (#1973) --- supervisor/const.py | 17 +++++++++++------ supervisor/host/__init__.py | 19 +++++++++---------- tests/host/test_supported_features.py | 11 +++++++++++ 3 files changed, 31 insertions(+), 16 deletions(-) create mode 100644 tests/host/test_supported_features.py diff --git a/supervisor/const.py b/supervisor/const.py index 1a155ac60..0cc9f29f2 100644 --- a/supervisor/const.py +++ b/supervisor/const.py @@ -338,12 +338,6 @@ PRIVILEGED_ALL = [ PRIVILEGED_DAC_READ_SEARCH, ] -FEATURES_SHUTDOWN = "shutdown" -FEATURES_REBOOT = "reboot" -FEATURES_HASSOS = "hassos" -FEATURES_HOSTNAME = "hostname" -FEATURES_SERVICES = "services" - ROLE_DEFAULT = "default" ROLE_HOMEASSISTANT = "homeassistant" ROLE_BACKUP = "backup" @@ -403,3 +397,14 @@ class LogLevel(str, Enum): WARNING = "warning" ERROR = "error" CRITICAL = "critical" + + +class HostFeature(str, Enum): + """Host feature.""" + + HASSOS = "hassos" + HOSTNAME = "hostname" + NETWORK = "network" + REBOOT = "reboot" + SERVICES = "services" + SHUTDOWN = "shutdown" diff --git a/supervisor/host/__init__.py b/supervisor/host/__init__.py index 4d9d69f95..c030e4172 100644 --- a/supervisor/host/__init__.py +++ b/supervisor/host/__init__.py @@ -2,13 +2,7 @@ from contextlib import suppress import logging -from ..const import ( - FEATURES_HASSOS, - FEATURES_HOSTNAME, - FEATURES_REBOOT, - FEATURES_SERVICES, - FEATURES_SHUTDOWN, -) +from ..const import HostFeature from ..coresys import CoreSys, CoreSysAttributes from ..exceptions import HassioError, PulseAudioError from .apparmor import AppArmorControl @@ -71,13 +65,18 @@ class HostManager(CoreSysAttributes): features = [] if self.sys_dbus.systemd.is_connected: - features.extend([FEATURES_REBOOT, FEATURES_SHUTDOWN, FEATURES_SERVICES]) + features.extend( + [HostFeature.REBOOT, HostFeature.SHUTDOWN, HostFeature.SERVICES] + ) + + if self.sys_dbus.network.is_connected: + features.append(HostFeature.NETWORK) if self.sys_dbus.hostname.is_connected: - features.append(FEATURES_HOSTNAME) + features.append(HostFeature.HOSTNAME) if self.sys_hassos.available: - features.append(FEATURES_HASSOS) + features.append(HostFeature.HASSOS) return features diff --git a/tests/host/test_supported_features.py b/tests/host/test_supported_features.py new file mode 100644 index 000000000..048586ed4 --- /dev/null +++ b/tests/host/test_supported_features.py @@ -0,0 +1,11 @@ +"""Test supported features.""" +# pylint: disable=protected-access + + +def test_supported_features(coresys): + """Test host features.""" + assert "network" in coresys.host.supported_features + + coresys._dbus.network.is_connected = False + + assert "network" not in coresys.host.supported_features