From ef782a293b43d3059bf96ce4078fe757169bc2a2 Mon Sep 17 00:00:00 2001 From: Aidan Timson Date: Fri, 9 Oct 2026 09:23:13 +0100 Subject: [PATCH] Bump systembridgeconnector to 5.5.0 (#185220) --- .../components/system_bridge/__init__.py | 10 +++++++ .../components/system_bridge/binary_sensor.py | 2 +- .../components/system_bridge/data.py | 6 ++--- .../components/system_bridge/entity.py | 15 ++++++----- .../components/system_bridge/manifest.json | 2 +- .../components/system_bridge/sensor.py | 24 +++++++++++------ .../components/system_bridge/update.py | 12 ++++++--- requirements_all.txt | 2 +- tests/components/system_bridge/test_init.py | 27 +++++++++++++++++++ 9 files changed, 76 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/system_bridge/__init__.py b/homeassistant/components/system_bridge/__init__.py index 034ac51ddfa9..d73d7247f00f 100644 --- a/homeassistant/components/system_bridge/__init__.py +++ b/homeassistant/components/system_bridge/__init__.py @@ -160,6 +160,16 @@ async def async_setup_entry( }, ) from exception + if coordinator.data.system is None: + raise ConfigEntryNotReady( + translation_domain=DOMAIN, + translation_key="timeout", + translation_placeholders={ + "title": entry.title, + "host": entry.data[CONF_HOST], + }, + ) + # Fetch initial data so we have data when entities subscribe await coordinator.async_config_entry_first_refresh() diff --git a/homeassistant/components/system_bridge/binary_sensor.py b/homeassistant/components/system_bridge/binary_sensor.py index 50e553524645..a14e4b6bb1ce 100644 --- a/homeassistant/components/system_bridge/binary_sensor.py +++ b/homeassistant/components/system_bridge/binary_sensor.py @@ -27,7 +27,7 @@ class SystemBridgeBinarySensorEntityDescription(BinarySensorEntityDescription): def camera_in_use(data: SystemBridgeData) -> bool | None: """Return if any camera is in use.""" - if data.system.camera_usage is not None: + if data.system is not None and data.system.camera_usage is not None: return len(data.system.camera_usage) > 0 return None diff --git a/homeassistant/components/system_bridge/data.py b/homeassistant/components/system_bridge/data.py index 983b16a20d43..252b41287af2 100644 --- a/homeassistant/components/system_bridge/data.py +++ b/homeassistant/components/system_bridge/data.py @@ -21,10 +21,10 @@ class SystemBridgeData: battery: Battery = field(default_factory=Battery) cpu: CPU = field(default_factory=CPU) - disks: Disks = None + disks: Disks | None = None displays: list[Display] = field(default_factory=list[Display]) gpus: list[GPU] = field(default_factory=list[GPU]) media: Media = field(default_factory=Media) - memory: Memory = None + memory: Memory | None = None processes: list[Process] = field(default_factory=list[Process]) - system: System = None + system: System | None = None diff --git a/homeassistant/components/system_bridge/entity.py b/homeassistant/components/system_bridge/entity.py index f2b89789e603..fc8369a97cee 100644 --- a/homeassistant/components/system_bridge/entity.py +++ b/homeassistant/components/system_bridge/entity.py @@ -22,18 +22,19 @@ class SystemBridgeEntity(CoordinatorEntity[SystemBridgeDataUpdateCoordinator]): """Initialize the System Bridge entity.""" super().__init__(coordinator) - self._hostname = coordinator.data.system.hostname + system = coordinator.data.system + assert system is not None + + self._hostname = system.hostname self._attr_unique_id = ( - f"{coordinator.data.system.uuid}_{key}" - if key is not None - else coordinator.data.system.uuid + f"{system.uuid}_{key}" if key is not None else system.uuid ) self._configuration_url = ( f"http://{self._hostname}:{api_port}/app/settings.html" ) - self._mac_address = coordinator.data.system.mac_address - self._uuid = coordinator.data.system.uuid - self._version = coordinator.data.system.version + self._mac_address = system.mac_address + self._uuid = system.uuid + self._version = system.version self._attr_device_info = DeviceInfo( configuration_url=self._configuration_url, diff --git a/homeassistant/components/system_bridge/manifest.json b/homeassistant/components/system_bridge/manifest.json index 4b4289c3cb91..8e944265c98d 100644 --- a/homeassistant/components/system_bridge/manifest.json +++ b/homeassistant/components/system_bridge/manifest.json @@ -9,6 +9,6 @@ "integration_type": "device", "iot_class": "local_push", "loggers": ["systembridgeconnector"], - "requirements": ["systembridgeconnector==5.4.3"], + "requirements": ["systembridgeconnector==5.5.0"], "zeroconf": ["_system-bridge._tcp.local."] } diff --git a/homeassistant/components/system_bridge/sensor.py b/homeassistant/components/system_bridge/sensor.py index 46cb21a8981f..9d3440eab2bd 100644 --- a/homeassistant/components/system_bridge/sensor.py +++ b/homeassistant/components/system_bridge/sensor.py @@ -191,18 +191,22 @@ def gpu_usage_percentage(gpu: GPU) -> float | None: def memory_free(data: SystemBridgeData) -> float | None: """Return the free memory.""" - if (virtual := data.memory.virtual) is not None and ( - free := virtual.free - ) is not None: + if ( + data.memory is not None + and (virtual := data.memory.virtual) is not None + and (free := virtual.free) is not None + ): return round(free / 1000**3, 2) return None def memory_used(data: SystemBridgeData) -> float | None: """Return the used memory.""" - if (virtual := data.memory.virtual) is not None and ( - used := virtual.used - ) is not None: + if ( + data.memory is not None + and (virtual := data.memory.virtual) is not None + and (used := virtual.used) is not None + ): return round(used / 1000**3, 2) return None @@ -214,7 +218,8 @@ def partition_usage( ) -> float | None: """Return the used memory.""" if ( - (devices := data.disks.devices) is not None + data.disks is not None + and (devices := data.disks.devices) is not None and device_index < len(devices) and (partitions := devices[device_index].partitions) is not None and partition_index < len(partitions) @@ -371,7 +376,10 @@ async def async_setup_entry( for description in BASE_SENSOR_TYPES ] - for index_device, device in enumerate(coordinator.data.disks.devices): + disk_devices = ( + coordinator.data.disks.devices if coordinator.data.disks is not None else [] + ) + for index_device, device in enumerate(disk_devices): if device.partitions is None: continue diff --git a/homeassistant/components/system_bridge/update.py b/homeassistant/components/system_bridge/update.py index b0b910d8a6ae..04893edd3a48 100644 --- a/homeassistant/components/system_bridge/update.py +++ b/homeassistant/components/system_bridge/update.py @@ -52,16 +52,22 @@ class SystemBridgeUpdateEntity(SystemBridgeEntity, UpdateEntity): @override def installed_version(self) -> str | None: """Version installed and in use.""" - return self.coordinator.data.system.version + if (system := self.coordinator.data.system) is None: + return None + return system.version @property @override def latest_version(self) -> str | None: """Latest version available for install.""" - return self.coordinator.data.system.version_latest + if (system := self.coordinator.data.system) is None: + return None + return system.version_latest @property @override def release_url(self) -> str | None: """URL to the full release notes of the latest version available.""" - return f"https://github.com/timmo001/system-bridge/releases/tag/{self.coordinator.data.system.version_latest}" + if (system := self.coordinator.data.system) is None: + return None + return f"https://github.com/timmo001/system-bridge/releases/tag/{system.version_latest}" diff --git a/requirements_all.txt b/requirements_all.txt index a53c608d01e3..8de87e22fa7f 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -3202,7 +3202,7 @@ switchbot-api==2.13.0 synology-srm==0.2.0 # homeassistant.components.system_bridge -systembridgeconnector==5.4.3 +systembridgeconnector==5.5.0 # homeassistant.components.tailscale tailscale==0.7.0 diff --git a/tests/components/system_bridge/test_init.py b/tests/components/system_bridge/test_init.py index 72296da8bd41..1f2565c724ed 100644 --- a/tests/components/system_bridge/test_init.py +++ b/tests/components/system_bridge/test_init.py @@ -204,3 +204,30 @@ async def test_coordinator_get_data_timeout(hass: HomeAssistant) -> None: assert result is False assert config_entry.state is ConfigEntryState.SETUP_RETRY + + +async def test_coordinator_get_data_missing_system(hass: HomeAssistant) -> None: + """Test setup retries when get_data returns without system data.""" + config_entry = MockConfigEntry( + domain=DOMAIN, + unique_id=FIXTURE_UUID, + data=FIXTURE_USER_INPUT, + version=SystemBridgeConfigFlow.VERSION, + minor_version=SystemBridgeConfigFlow.MINOR_VERSION, + ) + + with ( + patch( + "systembridgeconnector.version.Version.check_supported", + return_value=True, + ), + patch( + "homeassistant.components.system_bridge.coordinator.SystemBridgeDataUpdateCoordinator.async_get_data", + ), + ): + config_entry.add_to_hass(hass) + result = await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + + assert result is False + assert config_entry.state is ConfigEntryState.SETUP_RETRY