Compare commits

...

1 Commits

Author SHA1 Message Date
Claude 262aa26391 Fix Roborock number entity crash when volume is None
The volume number entity called float() directly on the trait value,
raising a TypeError when the device reports no volume (None). Return
None in that case so the entity reports an unknown state instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015muhdayAokSd8W9u2QYVJk
2026-06-25 01:12:35 +00:00
2 changed files with 22 additions and 3 deletions
+4 -2
View File
@@ -35,7 +35,7 @@ class RoborockNumberDescription(NumberEntityDescription):
trait: Callable[[PropertiesApi], Any | None]
"""Function to determine if number entity is supported by the device."""
get_value: Callable[[Any], float]
get_value: Callable[[Any], float | None]
"""Function to get the value from the trait."""
set_value: Callable[[Any, float], Coroutine[Any, Any, None]]
@@ -51,7 +51,9 @@ NUMBER_DESCRIPTIONS: list[RoborockNumberDescription] = [
native_unit_of_measurement=PERCENTAGE,
entity_category=EntityCategory.CONFIG,
trait=lambda api: api.sound_volume,
get_value=lambda trait: float(trait.volume),
get_value=lambda trait: (
float(trait.volume) if trait.volume is not None else None
),
set_value=lambda trait, value: trait.set_volume(int(value)),
)
]
+18 -1
View File
@@ -4,9 +4,10 @@ import pytest
from roborock.exceptions import RoborockTimeout
from homeassistant.components.number import ATTR_VALUE, SERVICE_SET_VALUE
from homeassistant.const import Platform
from homeassistant.const import STATE_UNKNOWN, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_component import async_update_entity
from .conftest import FakeDevice
@@ -49,6 +50,22 @@ async def test_update_sound_volume(
assert state.state == "3.0"
async def test_volume_unknown_value(
hass: HomeAssistant,
setup_entry: MockConfigEntry,
fake_vacuum: FakeDevice,
) -> None:
"""Test the entity reports unknown when the trait value is None."""
assert fake_vacuum.v1_properties is not None
fake_vacuum.v1_properties.sound_volume.volume = None
await async_update_entity(hass, "number.roborock_s7_maxv_volume")
state = hass.states.get("number.roborock_s7_maxv_volume")
assert state is not None
assert state.state == STATE_UNKNOWN
async def test_volume_update_failed(
hass: HomeAssistant,
setup_entry: MockConfigEntry,