Skip to content
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

When comparing state values in update() make sure both values are the same type #294

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion control/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,12 @@ def _update_caller(self, notify_event):
notify_event.wait(max(update_time - time.time(), 0))
notify_event.clear()

def compare_state_values(self, val1, val2) -> bool:
# We sometimes get one value as type bytes and the other as type str, so convert them both to str for the comparison
val1_str = val1.decode() if type(val1) == type(b'') else val1
val2_str = val2.decode() if type(val2) == type(b'') else val2
return val1_str == val2_str

def update(self):
"""Checks for updated omap state and initiates local update."""
prefix_list = [
Expand All @@ -457,7 +463,7 @@ def update(self):
changed = {
key: omap_state_dict[key]
for key in same_keys
if omap_state_dict[key] != local_state_dict[key]
if not self.compare_state_values(local_state_dict[key], omap_state_dict[key])
}
grouped_changed = self._group_by_prefix(changed, prefix_list)
# Find OMAP removals
Expand Down