Avoid keyerror on incomplete api data in myuplink (#136333)

* Avoid keyerror

* Inject erroneous value in device point fixture

* Update diagnostics snapshot
pull/136407/head
Åke Strandberg 2025-01-23 18:04:00 +01:00 committed by Franck Nijhof
parent 1f8129f4b8
commit 4cf1b1a707
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
4 changed files with 9 additions and 9 deletions

View File

@ -325,10 +325,10 @@ class MyUplinkEnumSensor(MyUplinkDevicePointSensor):
}
@property
def native_value(self) -> str:
def native_value(self) -> str | None:
"""Sensor state value for enum sensor."""
device_point = self.coordinator.data.points[self.device_id][self.point_id]
return self.options_map[str(int(device_point.value))] # type: ignore[no-any-return]
return self.options_map.get(str(int(device_point.value)))
class MyUplinkEnumRawSensor(MyUplinkDevicePointSensor):

View File

@ -822,7 +822,7 @@
"parameterUnit": "",
"writable": false,
"timestamp": "2024-02-08T19:13:05+00:00",
"value": 30,
"value": 31,
"strVal": "Heating",
"smartHomeCategories": [],
"minValue": null,

View File

@ -883,7 +883,7 @@
"parameterUnit": "",
"writable": false,
"timestamp": "2024-02-08T19:13:05+00:00",
"value": 30,
"value": 31,
"strVal": "Heating",
"smartHomeCategories": [],
"minValue": null,
@ -2045,7 +2045,7 @@
"parameterUnit": "",
"writable": false,
"timestamp": "2024-02-08T19:13:05+00:00",
"value": 30,
"value": 31,
"strVal": "Heating",
"smartHomeCategories": [],
"minValue": null,

View File

@ -3396,7 +3396,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'Heating',
'state': 'unknown',
})
# ---
# name: test_sensor_states[sensor.gotham_city_priority_2-entry]
@ -3462,7 +3462,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'Heating',
'state': 'unknown',
})
# ---
# name: test_sensor_states[sensor.gotham_city_priority_raw-entry]
@ -3508,7 +3508,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '30',
'state': '31',
})
# ---
# name: test_sensor_states[sensor.gotham_city_priority_raw_2-entry]
@ -3554,7 +3554,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '30',
'state': '31',
})
# ---
# name: test_sensor_states[sensor.gotham_city_r_start_diff_additional_heat-entry]