@@ -121,26 +121,31 @@ def __init__(self):
121121
122122 def apply_data (self , data : dict ):
123123 """Apply the given data dictionary."""
124- self ._device_id = data [ "deviceId" ]
125- self ._name = data [ "name" ]
126- self ._label = data [ "label" ]
127- self ._location_id = data [ "locationId" ]
124+ self ._device_id = data . get ( "deviceId" )
125+ self ._name = data . get ( "name" )
126+ self ._label = data . get ( "label" )
127+ self ._location_id = data . get ( "locationId" )
128128 self ._room_id = data .get ("roomId" )
129- self ._type = data [ "type" ]
129+ self ._type = data . get ( "type" )
130130 self ._components .clear ()
131131 self ._capabilities .clear ()
132- for component in data ["components" ]:
133- capabilities = [c ["id" ] for c in component ["capabilities" ]]
134- component_id = component ["id" ]
135- if component_id == "main" :
136- self ._capabilities .extend (capabilities )
137- else :
138- self ._components [component_id ] = capabilities
132+
133+ components = data .get ("components" )
134+ if components :
135+ for component in components :
136+ capabilities = [c ["id" ] for c in component ["capabilities" ]]
137+ component_id = component ["id" ]
138+ if component_id == "main" :
139+ self ._capabilities .extend (capabilities )
140+ else :
141+ self ._components [component_id ] = capabilities
142+
139143 if self ._type == DEVICE_TYPE_DTH :
140- dth = data ["dth" ]
141- self ._device_type_id = dth ["deviceTypeId" ]
142- self ._device_type_name = dth ["deviceTypeName" ]
143- self ._device_type_network = dth ["deviceNetworkType" ]
144+ dth = data .get ("dth" )
145+ if dth :
146+ self ._device_type_id = dth .get ("deviceTypeId" )
147+ self ._device_type_name = dth .get ("deviceTypeName" )
148+ self ._device_type_network = dth .get ("deviceNetworkType" )
144149
145150 def get_capability (self , * capabilities ) -> Optional [str ]:
146151 """Return the first capability held by the device."""
0 commit comments