mirror of
https://github.com/home-assistant/core.git
synced 2026-10-06 22:38:02 -04:00
Fix Hue temperature sensor crash on None value (#184148)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c9f1e5d3ef
commit
4c2f1dfed8
@@ -149,8 +149,10 @@ class HueTemperatureSensor(HueSensorBase):
|
||||
|
||||
@property
|
||||
@override
|
||||
def native_value(self) -> float:
|
||||
def native_value(self) -> float | None:
|
||||
"""Return the value reported by the sensor."""
|
||||
if self.resource.temperature.value is None:
|
||||
return None
|
||||
return round(self.resource.temperature.value, 1)
|
||||
|
||||
|
||||
|
||||
@@ -187,6 +187,24 @@ async def test_grouped_light_level_sensor(
|
||||
) # Light level 30000 translates to 10^((30000-1)/10000) ≈ 999 lux
|
||||
|
||||
|
||||
async def test_temperature_sensor_none_value(
|
||||
hass: HomeAssistant, mock_bridge_v2: Mock, v2_resources_test_data: JsonArrayType
|
||||
) -> None:
|
||||
"""Test that temperature sensor handles None value without crashing."""
|
||||
for resource in v2_resources_test_data:
|
||||
if resource.get("id") == "66466e14-d2fa-4b96-b2a0-e10de9cd8b8b":
|
||||
resource["temperature"]["temperature"] = None
|
||||
resource["temperature"]["temperature_valid"] = False
|
||||
break
|
||||
|
||||
await mock_bridge_v2.api.load_test_data(v2_resources_test_data)
|
||||
await setup_platform(hass, mock_bridge_v2, Platform.SENSOR)
|
||||
|
||||
sensor = hass.states.get("sensor.hue_motion_sensor_temperature")
|
||||
assert sensor is not None
|
||||
assert sensor.state == STATE_UNKNOWN
|
||||
|
||||
|
||||
async def test_light_level_sensor_none_value(
|
||||
hass: HomeAssistant, mock_bridge_v2: Mock, v2_resources_test_data: JsonArrayType
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user