-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic load timeout #78
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
30c7aac
Dynamic load timeout
brefra 34ff42c
Throttle module loading
brefra c4f4b4c
Bump version to 2.1.4
brefra 9cfc7da
Don't load modules while loading is running
brefra 02987fa
Rename _load_in_progress into _loading_triggered
brefra 611aff9
Request channel names at 2nd reload
brefra 1982b4e
Add 2nd try to load modules
brefra af929ab
Import specific datetime modules
brefra fe27e1d
Reduce comment
brefra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
""" | ||
:author: Thomas Delaet <[email protected]> | ||
""" | ||
import datetime | ||
import string | ||
import struct | ||
from velbus.messages.read_data_from_memory import ReadDataFromMemoryMessage | ||
|
@@ -39,7 +40,9 @@ def __init__(self, module_type, module_name, module_address, controller): | |
|
||
self._loaded_callbacks = [] | ||
self.loaded = False | ||
self._loading_triggered = False | ||
|
||
self._last_channel_name_msg = datetime.datetime.utcnow() | ||
self._controller = controller | ||
self._controller.subscribe(self.on_message) | ||
|
||
|
@@ -148,18 +151,33 @@ def load(self, callback): | |
""" | ||
Retrieve names of channels | ||
""" | ||
if not self._is_submodule(): | ||
# load the data from memory ( the stuff that we need) | ||
self._load_memory() | ||
# load the module status | ||
self._request_module_status() | ||
if not self._is_submodule(): | ||
# load the channel names | ||
self._request_channel_name() | ||
if callback: | ||
self._loaded_callbacks.append(callback) | ||
# load the module specific stuff | ||
self._load() | ||
if not self.loaded: | ||
if not self._loading_triggered: | ||
self._loading_triggered = True | ||
if not self._is_submodule(): | ||
# load the data from memory ( the stuff that we need) | ||
self._load_memory() | ||
# load the module status | ||
self._request_module_status() | ||
if not self._is_submodule(): | ||
# load the channel names | ||
self._request_channel_name() | ||
# load the module specific stuff | ||
self._load() | ||
else: | ||
# Request channel names if last received | ||
if ( | ||
not self._is_submodule() | ||
and not self._name_messages_complete() | ||
and self._last_channel_name_msg | ||
< datetime.datetime.utcnow() - datetime.timedelta(seconds=10) | ||
): | ||
self._request_channel_name() | ||
if callback: | ||
self._loaded_callbacks.append(callback) | ||
else: | ||
if callback: | ||
callback() | ||
|
||
def loading_in_progress(self): | ||
return not self._name_messages_complete() | ||
|
@@ -185,6 +203,7 @@ def _name_count_needed(self): | |
return self.number_of_channels() * 3 | ||
|
||
def _process_channel_name_message(self, part, message): | ||
self._last_channel_name_msg = datetime.datetime.utcnow() | ||
channel = message.channel | ||
if self._is_submodule(): | ||
channel = channel - (self.number_of_channels() * self.sub_module) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (81 > 79 characters)