From 766523cf8cda9f3cae68a25d48388a62aa4919f0 Mon Sep 17 00:00:00 2001 From: Benoit Anastay <45088785+BenoitAnastay@users.noreply.github.com> Date: Fri, 8 Jul 2022 23:22:31 +0200 Subject: [PATCH] Fix error with HDD temperature report in Freebox integration (#74718) * Fix error whith HDD temperature report There was a non handled error case, documented in issue https://github.com/home-assistant/core/issues/43812 back in 2020 and the fix wasn't applied * Use get method instead of ignoring the sensor * Update test values Add idle state drive with unkown temp * update Tests for system sensors api * Fix booleans values * Fix disk unique_id There was a typo in the code --- homeassistant/components/freebox/router.py | 2 +- homeassistant/components/freebox/sensor.py | 2 +- tests/components/freebox/const.py | 38 +++++++++++++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/freebox/router.py b/homeassistant/components/freebox/router.py index 70fc7b86a40..ce4d03aae7a 100644 --- a/homeassistant/components/freebox/router.py +++ b/homeassistant/components/freebox/router.py @@ -113,7 +113,7 @@ class FreeboxRouter: # According to the doc `syst_datas["sensors"]` is temperature sensors in celsius degree. # Name and id of sensors may vary under Freebox devices. for sensor in syst_datas["sensors"]: - self.sensors_temperature[sensor["name"]] = sensor["value"] + self.sensors_temperature[sensor["name"]] = sensor.get("value") # Connection sensors connection_datas: dict[str, Any] = await self._api.connection.get_status() diff --git a/homeassistant/components/freebox/sensor.py b/homeassistant/components/freebox/sensor.py index 46aa9ee8aa0..450456b9146 100644 --- a/homeassistant/components/freebox/sensor.py +++ b/homeassistant/components/freebox/sensor.py @@ -159,7 +159,7 @@ class FreeboxDiskSensor(FreeboxSensor): self._disk = disk self._partition = partition self._attr_name = f"{partition['label']} {description.name}" - self._unique_id = f"{self._router.mac} {description.key} {self._disk['id']} {self._partition['id']}" + self._attr_unique_id = f"{self._router.mac} {description.key} {self._disk['id']} {self._partition['id']}" @property def device_info(self) -> DeviceInfo: diff --git a/tests/components/freebox/const.py b/tests/components/freebox/const.py index cc3d720d7ef..25402cbcdef 100644 --- a/tests/components/freebox/const.py +++ b/tests/components/freebox/const.py @@ -22,6 +22,7 @@ DATA_SYSTEM_GET_CONFIG = { "fans": [{"id": "fan0_speed", "name": "Ventilateur 1", "value": 2130}], "sensors": [ {"id": "temp_hdd", "name": "Disque dur", "value": 40}, + {"id": "temp_hdd2", "name": "Disque dur 2"}, {"id": "temp_sw", "name": "Température Switch", "value": 50}, {"id": "temp_cpum", "name": "Température CPU M", "value": 60}, {"id": "temp_cpub", "name": "Température CPU B", "value": 56}, @@ -123,7 +124,42 @@ DATA_STORAGE_GET_DISKS = [ "path": "L0Rpc3F1ZSBkdXI=", } ], - } + }, + { + "idle_duration": 8290, + "read_error_requests": 0, + "read_requests": 2326826, + "spinning": False, + "table_type": "gpt", + "firmware": "0001", + "type": "sata", + "idle": True, + "connector": 0, + "id": 2000, + "write_error_requests": 0, + "state": "enabled", + "write_requests": 122733632, + "total_bytes": 2000000000000, + "model": "ST2000LM015-2E8174", + "active_duration": 0, + "temp": 0, + "serial": "WDZYJ27Q", + "partitions": [ + { + "fstype": "ext4", + "total_bytes": 1960000000000, + "label": "Disque 2", + "id": 2001, + "internal": False, + "fsck_result": "no_run_yet", + "state": "mounted", + "disk_id": 2000, + "free_bytes": 1880000000000, + "used_bytes": 85410000000, + "path": "L0Rpc3F1ZSAy", + } + ], + }, ] # switch