diff --git a/supervisor/dbus/systemd.py b/supervisor/dbus/systemd.py index 31fa1531c..a18b6f406 100644 --- a/supervisor/dbus/systemd.py +++ b/supervisor/dbus/systemd.py @@ -112,6 +112,12 @@ class Systemd(DBusInterfaceProxy): "No systemd support on the host. Host control has been disabled." ) + if self.is_connected: + try: + await self.connected_dbus.Manager.call("subscribe") + except DBusError: + _LOGGER.warning("Could not subscribe to systemd signals") + @property @dbus_property def startup_time(self) -> float: diff --git a/tests/dbus/test_systemd.py b/tests/dbus/test_systemd.py index 09fb22574..6489d0e95 100644 --- a/tests/dbus/test_systemd.py +++ b/tests/dbus/test_systemd.py @@ -32,6 +32,18 @@ async def test_dbus_systemd_info(dbus_session_bus: MessageBus): assert systemd.startup_time == 45.304696 +async def test_subscribe_on_connect( + systemd_service: SystemdService, dbus_session_bus: MessageBus +): + """Test that Subscribe is called on connect to enable signal emission.""" + systemd_service.Subscribe.calls.clear() + systemd = Systemd() + + await systemd.connect(dbus_session_bus) + + assert systemd_service.Subscribe.calls == [()] + + async def test_reboot(systemd_service: SystemdService, dbus_session_bus: MessageBus): """Test reboot.""" systemd_service.Reboot.calls.clear() diff --git a/tests/dbus_service_mocks/systemd.py b/tests/dbus_service_mocks/systemd.py index fd4a59200..4ebb3f035 100644 --- a/tests/dbus_service_mocks/systemd.py +++ b/tests/dbus_service_mocks/systemd.py @@ -656,6 +656,10 @@ class Systemd(DBusServiceMock): def PowerOff(self) -> None: """Power off host computer.""" + @dbus_method() + def Subscribe(self) -> None: + """Subscribe to systemd signals.""" + @dbus_method() def StartUnit(self, name: "s", mode: "s") -> "o": """Start a service unit."""