1 """Support for Roborock number."""
4 from collections.abc
import Callable, Coroutine
5 from dataclasses
import dataclass
9 from roborock.command_cache
import CacheableAttribute
10 from roborock.exceptions
import RoborockException
11 from roborock.version_1_apis.roborock_client_v1
import AttributeCache
19 from .
import DOMAIN, RoborockConfigEntry
20 from .coordinator
import RoborockDataUpdateCoordinator
21 from .entity
import RoborockEntityV1
23 _LOGGER = logging.getLogger(__name__)
26 @dataclass(frozen=True, kw_only=True)
28 """Class to describe a Roborock number entity."""
31 cache_key: CacheableAttribute
33 update_value: Callable[[AttributeCache, float], Coroutine[Any, Any,
None]]
36 NUMBER_DESCRIPTIONS: list[RoborockNumberDescription] = [
39 translation_key=
"volume",
42 native_unit_of_measurement=PERCENTAGE,
43 cache_key=CacheableAttribute.sound_volume,
44 entity_category=EntityCategory.CONFIG,
45 update_value=
lambda cache, value: cache.update_value([
int(value)]),
52 config_entry: RoborockConfigEntry,
53 async_add_entities: AddEntitiesCallback,
55 """Set up Roborock number platform."""
56 possible_entities: list[
57 tuple[RoborockDataUpdateCoordinator, RoborockNumberDescription]
59 (coordinator, description)
60 for coordinator
in config_entry.runtime_data.v1
61 for description
in NUMBER_DESCRIPTIONS
64 results = await asyncio.gather(
66 coordinator.api.get_from_cache(description.cache_key)
67 for coordinator, description
in possible_entities
69 return_exceptions=
True,
71 valid_entities: list[RoborockNumberEntity] = []
72 for (coordinator, description), result
in zip(
73 possible_entities, results, strict=
False
75 if result
is None or isinstance(result, RoborockException):
76 _LOGGER.debug(
"Not adding entity because of %s", result)
78 valid_entities.append(
80 f
"{description.key}_{coordinator.duid_slug}",
89 """A class to let you set options on a Roborock vacuum where the potential options are fixed."""
91 entity_description: RoborockNumberDescription
96 coordinator: RoborockDataUpdateCoordinator,
97 entity_description: RoborockNumberDescription,
99 """Create a number entity."""
101 super().
__init__(unique_id, coordinator.device_info, coordinator.api)
105 """Get native value."""
110 """Set number value."""
115 except RoborockException
as err:
117 translation_domain=DOMAIN,
118 translation_key=
"update_options_failed",
AttributeCache get_cache(self, CacheableAttribute attribute)
None __init__(self, str unique_id, RoborockDataUpdateCoordinator coordinator, RoborockNumberDescription entity_description)
None async_set_native_value(self, float value)
float|None native_value(self)
None async_setup_entry(HomeAssistant hass, RoborockConfigEntry config_entry, AddEntitiesCallback async_add_entities)