44import string
55import struct
66from velbus .messages .read_data_from_memory import ReadDataFromMemoryMessage
7+ from datetime import datetime , timedelta
78from velbus .messages .memory_data import MemoryDataMessage
89from velbus .messages .channel_name_part1 import ChannelNamePart1Message
910from velbus .messages .channel_name_part1 import ChannelNamePart1Message2
@@ -39,7 +40,9 @@ def __init__(self, module_type, module_name, module_address, controller):
3940
4041 self ._loaded_callbacks = []
4142 self .loaded = False
43+ self ._loading_triggered = False
4244
45+ self ._last_channel_name_msg = datetime .utcnow ()
4346 self ._controller = controller
4447 self ._controller .subscribe (self .on_message )
4548
@@ -148,18 +151,33 @@ def load(self, callback):
148151 """
149152 Retrieve names of channels
150153 """
151- if not self ._is_submodule ():
152- # load the data from memory ( the stuff that we need)
153- self ._load_memory ()
154- # load the module status
155- self ._request_module_status ()
156- if not self ._is_submodule ():
157- # load the channel names
158- self ._request_channel_name ()
159- if callback :
160- self ._loaded_callbacks .append (callback )
161- # load the module specific stuff
162- self ._load ()
154+ if not self .loaded :
155+ if not self ._loading_triggered :
156+ self ._loading_triggered = True
157+ if not self ._is_submodule ():
158+ # load the data from memory ( the stuff that we need)
159+ self ._load_memory ()
160+ # load the module status
161+ self ._request_module_status ()
162+ if not self ._is_submodule ():
163+ # load the channel names
164+ self ._request_channel_name ()
165+ # load the module specific stuff
166+ self ._load ()
167+ else :
168+ # Request channel names if last received
169+ if (
170+ not self ._is_submodule ()
171+ and not self ._name_messages_complete ()
172+ and self ._last_channel_name_msg
173+ < datetime .utcnow () - timedelta (seconds = 10 )
174+ ):
175+ self ._request_channel_name ()
176+ if callback :
177+ self ._loaded_callbacks .append (callback )
178+ else :
179+ if callback :
180+ callback ()
163181
164182 def loading_in_progress (self ):
165183 return not self ._name_messages_complete ()
@@ -185,6 +203,7 @@ def _name_count_needed(self):
185203 return self .number_of_channels () * 3
186204
187205 def _process_channel_name_message (self , part , message ):
206+ self ._last_channel_name_msg = datetime .utcnow ()
188207 channel = message .channel
189208 if self ._is_submodule ():
190209 channel = channel - (self .number_of_channels () * self .sub_module )
0 commit comments