@@ -162,13 +162,14 @@ def get_prefixed_host(self):
162162 else :
163163 return "http://" + host
164164
165- def update_devices (self ):
165+ def update_devices (self , ignore_removed = True ):
166166 """Update the device."""
167167 _LOGGER .info ("Updating Devices ..." )
168168 if self ._devices is None :
169169 self ._devices = {}
170170
171- for element in self .get_device_elements ():
171+ device_elements = self .get_device_elements ()
172+ for element in device_elements :
172173 if element .attrib ["identifier" ] in self ._devices .keys ():
173174 _LOGGER .info (
174175 "Updating already existing Device " + element .attrib ["identifier" ]
@@ -178,6 +179,15 @@ def update_devices(self):
178179 _LOGGER .info ("Adding new Device " + element .attrib ["identifier" ])
179180 device = FritzhomeDevice (self , node = element )
180181 self ._devices [device .ain ] = device
182+
183+ if not ignore_removed :
184+ for identifier in list (self ._devices .keys ()):
185+ if identifier not in [
186+ element .attrib ["identifier" ] for element in device_elements
187+ ]:
188+ _LOGGER .info ("Removing no more existing device " + identifier )
189+ self ._devices .pop (identifier )
190+
181191 return True
182192
183193 def _get_listinfo_elements (self , entity_type ):
@@ -280,9 +290,7 @@ def set_boost_mode(self, ain, seconds):
280290 """Set the thermostate to boost mode."""
281291 endtimestamp = int (time .time () + seconds )
282292
283- self ._aha_request (
284- "sethkrboost" , ain = ain , param = {"endtimestamp" : endtimestamp }
285- )
293+ self ._aha_request ("sethkrboost" , ain = ain , param = {"endtimestamp" : endtimestamp })
286294
287295 def get_comfort_temperature (self , ain ):
288296 """Get the thermostate comfort temperature."""
@@ -407,13 +415,14 @@ def has_templates(self):
407415 return False
408416 return True
409417
410- def update_templates (self ):
418+ def update_templates (self , ignore_removed = True ):
411419 """Update the template."""
412420 _LOGGER .info ("Updating Templates ..." )
413421 if self ._templates is None :
414422 self ._templates = {}
415423
416- for element in self .get_template_elements ():
424+ template_elements = self .get_template_elements ()
425+ for element in template_elements :
417426 if element .attrib ["identifier" ] in self ._templates .keys ():
418427 _LOGGER .info (
419428 "Updating already existing Template " + element .attrib ["identifier" ]
@@ -423,6 +432,15 @@ def update_templates(self):
423432 _LOGGER .info ("Adding new Template " + element .attrib ["identifier" ])
424433 template = FritzhomeTemplate (self , node = element )
425434 self ._templates [template .ain ] = template
435+
436+ if not ignore_removed :
437+ for identifier in list (self ._templates .keys ()):
438+ if identifier not in [
439+ element .attrib ["identifier" ] for element in template_elements
440+ ]:
441+ _LOGGER .info ("Removing no more existing template " + identifier )
442+ self ._templates .pop (identifier )
443+
426444 return True
427445
428446 def get_template_elements (self ):
0 commit comments