2626 - `requires_feature` - The string name of the device feature that must be supported
2727 for this trait to be enabled. See `DeviceFeaturesTrait` for a list of
2828 available features.
29- - `requires_dock_type` - If set, this trait requires the
30- device to have any of the specified dock types to be enabled. See
31- `RoborockDockTypeCode` for a list of available dock types.
29+ - `requires_dock_type` - If set, this is a function that accepts a `RoborockDockTypeCode`
30+ and returns a boolean indicating whether the trait is supported for that dock type.
3231"""
3332
3433import logging
5049from .consumeable import ConsumableTrait
5150from .device_features import DeviceFeaturesTrait
5251from .do_not_disturb import DoNotDisturbTrait
53- from .dock_summary import DockSummaryTrait
5452from .dust_collection_mode import DustCollectionModeTrait
5553from .flow_led_status import FlowLedStatusTrait
5654from .home import HomeTrait
8482 "FlowLedStatusTrait" ,
8583 "LedStatusTrait" ,
8684 "ValleyElectricityTimerTrait" ,
87- "DockSummaryTrait" ,
8885 "DustCollectionModeTrait" ,
8986 "WashTowelModeTrait" ,
9087 "SmartWashParamsTrait" ,
@@ -111,16 +108,15 @@ class PropertiesApi(Trait):
111108 consumables : ConsumableTrait
112109 home : HomeTrait
113110 device_features : DeviceFeaturesTrait
114- dust_collection_mode : DustCollectionModeTrait
115111
116112 # Optional features that may not be supported on all devices
117113 child_lock : ChildLockTrait | None = None
118114 led_status : LedStatusTrait | None = None
119115 flow_led_status : FlowLedStatusTrait | None = None
120116 valley_electricity_timer : ValleyElectricityTimerTrait | None = None
117+ dust_collection_mode : DustCollectionModeTrait | None = None
121118 wash_towel_mode : WashTowelModeTrait | None = None
122119 smart_wash_params : SmartWashParamsTrait | None = None
123- dock_summary : DockSummaryTrait | None = None
124120
125121 def __init__ (
126122 self ,
@@ -191,35 +187,21 @@ async def discover_features(self) -> None:
191187
192188 # Union args may not be in declared order
193189 item_type = union_args [0 ] if union_args [1 ] is type (None ) else union_args [1 ]
194- if item_type is DockSummaryTrait :
195- # DockSummaryTrait is created manually below
196- continue
197- trait = item_type ()
198- if not self ._is_supported (trait , item .name , dock_type ):
190+ if not self ._is_supported (item_type , item .name , dock_type ):
199191 _LOGGER .debug ("Trait '%s' not supported, skipping" , item .name )
200192 continue
201-
202193 _LOGGER .debug ("Trait '%s' is supported, initializing" , item .name )
194+ trait = item_type ()
203195 setattr (self , item .name , trait )
204196 trait ._rpc_channel = self ._get_rpc_channel (trait )
205197
206- if dock_type is None or dock_type == RoborockDockTypeCode .no_dock :
207- _LOGGER .debug ("Trait 'dock_summary' not supported, skipping" )
208- else :
209- _LOGGER .debug ("Trait 'dock_summary' is supported, initializing" )
210- self .dock_summary = DockSummaryTrait (
211- self .dust_collection_mode ,
212- self .wash_towel_mode ,
213- self .smart_wash_params ,
214- )
215-
216- def _is_supported (self , trait : V1TraitMixin , name : str , dock_type : RoborockDockTypeCode ) -> bool :
198+ def _is_supported (self , trait_type : type [V1TraitMixin ], name : str , dock_type : RoborockDockTypeCode ) -> bool :
217199 """Check if a trait is supported by the device."""
218200
219- if (requires_dock_type := getattr (trait , "requires_dock_type" , None )) is not None :
220- return dock_type in requires_dock_type
201+ if (requires_dock_type := getattr (trait_type , "requires_dock_type" , None )) is not None :
202+ return requires_dock_type ( dock_type )
221203
222- if (feature_name := getattr (trait , "requires_feature" , None )) is None :
204+ if (feature_name := getattr (trait_type , "requires_feature" , None )) is None :
223205 _LOGGER .debug ("Optional trait missing 'requires_feature' attribute %s, skipping" , name )
224206 return False
225207 if (is_supported := getattr (self .device_features , feature_name )) is None :
0 commit comments