roborock.devices.traits.v1.device_features
1from dataclasses import fields 2 3from roborock.data import AppInitStatus, RoborockProductNickname 4from roborock.device_features import DeviceFeatures 5from roborock.devices.cache import DeviceCache 6from roborock.devices.traits.v1 import common 7from roborock.roborock_typing import RoborockCommand 8 9 10class DeviceFeaturesTrait(DeviceFeatures, common.V1TraitMixin): 11 """Trait for managing Do Not Disturb (DND) settings on Roborock devices.""" 12 13 command = RoborockCommand.APP_GET_INIT_STATUS 14 15 def __init__(self, product_nickname: RoborockProductNickname, device_cache: DeviceCache) -> None: # pylint: disable=super-init-not-called 16 """Initialize MapContentTrait.""" 17 self._nickname = product_nickname 18 self._device_cache = device_cache 19 # All fields of DeviceFeatures are required. Initialize them to False 20 # so we have some known state. 21 for field in fields(self): 22 setattr(self, field.name, False) 23 24 async def refresh(self) -> None: 25 """Refresh the contents of this trait. 26 27 This will use cached device features if available since they do not 28 change often and this avoids unnecessary RPC calls. This would only 29 ever change with a firmware update, so caching is appropriate. 30 """ 31 cache_data = await self._device_cache.get() 32 if cache_data.device_features is not None: 33 self._update_trait_values(cache_data.device_features) 34 return 35 # Save cached device features 36 await super().refresh() 37 cache_data.device_features = self 38 await self._device_cache.set(cache_data) 39 40 def _parse_response(self, response: common.V1ResponseData) -> DeviceFeatures: 41 """Parse the response from the device into a MapContentTrait instance.""" 42 if not isinstance(response, list): 43 raise ValueError(f"Unexpected AppInitStatus response format: {type(response)}") 44 app_status = AppInitStatus.from_dict(response[0]) 45 return DeviceFeatures.from_feature_flags( 46 new_feature_info=app_status.new_feature_info, 47 new_feature_info_str=app_status.new_feature_info_str, 48 feature_info=app_status.feature_info, 49 product_nickname=self._nickname, 50 )
class
DeviceFeaturesTrait(roborock.device_features.DeviceFeatures, roborock.devices.traits.v1.common.V1TraitMixin):
11class DeviceFeaturesTrait(DeviceFeatures, common.V1TraitMixin): 12 """Trait for managing Do Not Disturb (DND) settings on Roborock devices.""" 13 14 command = RoborockCommand.APP_GET_INIT_STATUS 15 16 def __init__(self, product_nickname: RoborockProductNickname, device_cache: DeviceCache) -> None: # pylint: disable=super-init-not-called 17 """Initialize MapContentTrait.""" 18 self._nickname = product_nickname 19 self._device_cache = device_cache 20 # All fields of DeviceFeatures are required. Initialize them to False 21 # so we have some known state. 22 for field in fields(self): 23 setattr(self, field.name, False) 24 25 async def refresh(self) -> None: 26 """Refresh the contents of this trait. 27 28 This will use cached device features if available since they do not 29 change often and this avoids unnecessary RPC calls. This would only 30 ever change with a firmware update, so caching is appropriate. 31 """ 32 cache_data = await self._device_cache.get() 33 if cache_data.device_features is not None: 34 self._update_trait_values(cache_data.device_features) 35 return 36 # Save cached device features 37 await super().refresh() 38 cache_data.device_features = self 39 await self._device_cache.set(cache_data) 40 41 def _parse_response(self, response: common.V1ResponseData) -> DeviceFeatures: 42 """Parse the response from the device into a MapContentTrait instance.""" 43 if not isinstance(response, list): 44 raise ValueError(f"Unexpected AppInitStatus response format: {type(response)}") 45 app_status = AppInitStatus.from_dict(response[0]) 46 return DeviceFeatures.from_feature_flags( 47 new_feature_info=app_status.new_feature_info, 48 new_feature_info_str=app_status.new_feature_info_str, 49 feature_info=app_status.feature_info, 50 product_nickname=self._nickname, 51 )
Trait for managing Do Not Disturb (DND) settings on Roborock devices.
DeviceFeaturesTrait( product_nickname: roborock.data.code_mappings.RoborockProductNickname, device_cache: roborock.devices.cache.DeviceCache)
16 def __init__(self, product_nickname: RoborockProductNickname, device_cache: DeviceCache) -> None: # pylint: disable=super-init-not-called 17 """Initialize MapContentTrait.""" 18 self._nickname = product_nickname 19 self._device_cache = device_cache 20 # All fields of DeviceFeatures are required. Initialize them to False 21 # so we have some known state. 22 for field in fields(self): 23 setattr(self, field.name, False)
Initialize MapContentTrait.
async def
refresh(self) -> None:
25 async def refresh(self) -> None: 26 """Refresh the contents of this trait. 27 28 This will use cached device features if available since they do not 29 change often and this avoids unnecessary RPC calls. This would only 30 ever change with a firmware update, so caching is appropriate. 31 """ 32 cache_data = await self._device_cache.get() 33 if cache_data.device_features is not None: 34 self._update_trait_values(cache_data.device_features) 35 return 36 # Save cached device features 37 await super().refresh() 38 cache_data.device_features = self 39 await self._device_cache.set(cache_data)
Refresh the contents of this trait.
This will use cached device features if available since they do not change often and this avoids unnecessary RPC calls. This would only ever change with a firmware update, so caching is appropriate.