@@ -107,7 +107,6 @@ async def start(self) -> None:
107107 """Initialize load the network registry."""
108108 if self ._cache_enabled :
109109 await self .restore_network_cache ()
110- await self .load_registry_from_cache ()
111110 await self .update_missing_registrations_quick ()
112111
113112 async def restore_network_cache (self ) -> None :
@@ -121,22 +120,6 @@ async def restore_network_cache(self) -> None:
121120 await self ._network_cache .restore_cache ()
122121 self ._cache_restored = True
123122
124- async def load_registry_from_cache (self ) -> None :
125- """Load network registry from cache."""
126- if self ._network_cache is None :
127- _LOGGER .error (
128- "Unable to restore network registry because cache is not initialized"
129- )
130- return
131-
132- if self ._cache_restored :
133- return
134-
135- for address , registration in self ._network_cache .registrations .items ():
136- mac , node_type = registration
137- if self ._registry .get (address ) is None :
138- self ._registry [address ] = (mac , node_type )
139-
140123 async def retrieve_network_registration (
141124 self , address : int , retry : bool = True
142125 ) -> tuple [int , str ] | None :
@@ -167,17 +150,22 @@ def network_controller(self) -> tuple[str, NodeType | None]:
167150 raise NodeError ("Unable to return network controller details" )
168151 return self .registry [- 1 ]
169152
170- def update_network_registration (
153+ async def update_network_registration (
171154 self , address : int , mac : str , node_type : NodeType | None
172155 ) -> None :
173156 """Add a network registration."""
174- if self ._registry .get (address ) is not None :
175- _ , current_type = self ._registry [address ]
176- if current_type is not None and node_type is None :
177- return
157+ if node_type is None :
158+ if self ._registry .get (address ) is not None :
159+ _ , current_type = self ._registry [address ]
160+ if current_type is not None :
161+ return
162+ if self ._network_cache is not None :
163+ node_type = self ._network_cache ._nodetypes .get (mac )
164+
178165 self ._registry [address ] = (mac , node_type )
179- if self ._network_cache is not None :
180- self ._network_cache .update_registration (address , mac , node_type )
166+ if node_type is not None :
167+ if self ._network_cache is not None :
168+ await self ._network_cache .update_nodetypes (mac , node_type )
181169
182170 async def update_missing_registrations_full (self ) -> None :
183171 """Full retrieval of all unknown network registrations from network controller."""
@@ -199,14 +187,10 @@ async def update_missing_registrations_full(self) -> None:
199187 str (nextaddress ),
200188 "'empty'" if mac == "" else f"set to { mac } " ,
201189 )
202- self .update_network_registration (nextaddress , mac , None )
190+ await self .update_network_registration (nextaddress , mac , None )
203191 await sleep (10 )
204192 _LOGGER .debug ("Full network registration finished" )
205193 self ._scan_completed = True
206- if self ._cache_enabled :
207- _LOGGER .debug ("Full network registration finished, save to cache" )
208- await self .save_registry_to_cache ()
209- _LOGGER .debug ("Full network registration finished, post" )
210194 _LOGGER .info ("Full network discovery completed" )
211195 if self ._full_scan_finished is not None :
212196 await self ._full_scan_finished ()
@@ -228,7 +212,7 @@ async def update_missing_registrations_quick(self) -> None:
228212 str (nextaddress ),
229213 "'empty'" if mac == "" else f"set to { mac } " ,
230214 )
231- self .update_network_registration (nextaddress , mac , None )
215+ await self .update_network_registration (nextaddress , mac , None )
232216 await sleep (0.1 )
233217 if self ._registration_task is None or self ._registration_task .done ():
234218 self ._registration_task = create_task (
@@ -239,9 +223,9 @@ async def update_missing_registrations_quick(self) -> None:
239223 self ._quick_scan_finished = None
240224 _LOGGER .info ("Quick network registration discovery finished" )
241225
242- def update_node_registration (self , mac : str ) -> int :
226+ async def update_node_registration (self , mac : str ) -> int :
243227 """Register (re)joined node to Plugwise network and return network address."""
244- self .update_network_registration (self ._first_free_address , mac , None )
228+ await self .update_network_registration (self ._first_free_address , mac , None )
245229 self ._first_free_address += 1
246230 return self ._first_free_address - 1
247231
@@ -251,22 +235,6 @@ def _stop_registration_task(self) -> None:
251235 return
252236 self ._registration_task .cancel ()
253237
254- async def save_registry_to_cache (self ) -> None :
255- """Save network registry to cache."""
256- if self ._network_cache is None :
257- _LOGGER .error (
258- "Unable to save network registry because cache is not initialized"
259- )
260- return
261- _LOGGER .debug (
262- "save_registry_to_cache starting for %s items" , str (len (self ._registry ))
263- )
264- for address , registration in self ._registry .items ():
265- mac , node_type = registration
266- self ._network_cache .update_registration (address , mac , node_type )
267- await self ._network_cache .save_cache ()
268- _LOGGER .debug ("save_registry_to_cache finished" )
269-
270238 async def register_node (self , mac : str ) -> None :
271239 """Register node to Plugwise network and return network address."""
272240 if not validate_mac (mac ):
@@ -303,7 +271,7 @@ async def unregister_node(self, mac: str) -> None:
303271 + f" failed to unregister node '{ mac } '"
304272 )
305273 if (address := self .network_address (mac )) is not None :
306- self .update_network_registration (address , mac , None )
274+ await self .update_network_registration (address , mac , None )
307275
308276 async def clear_register_cache (self ) -> None :
309277 """Clear current cache."""
@@ -314,9 +282,3 @@ async def clear_register_cache(self) -> None:
314282 async def stop (self ) -> None :
315283 """Unload the network registry."""
316284 self ._stop_registration_task ()
317- if (
318- self ._cache_enabled
319- and self ._network_cache is not None
320- and self ._network_cache .initialized
321- ):
322- await self .save_registry_to_cache ()
0 commit comments