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

module websocket: fix for smartvisu protocol #680

Merged
merged 2 commits into from
Oct 13, 2024
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
47 changes: 28 additions & 19 deletions modules/websocket/smartvisu.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,32 +400,41 @@ async def prepare_monitor(self, data, client_addr):
items = []
newmonitor_items = []
for path in list(data['items']):
path_parts = 0 if path is None else path.split('.property.')
path_parts = [] if path is None else path.split('.property.')

# first identify item
item = self.items.return_item(path_parts[0])
if item is None:
self.logger.error(f"prepare_monitor: No item '{path}' found (requested by client {self.build_log_info(client_addr)}")
continue

# get item visu acl
item_acl = item.conf.get('acl', None)
if item_acl is None:
item_acl = self.sv_acl

# if acl is deny, don't add item or property
if item_acl == 'deny':
# log deny to indicate feature, not bug?
continue

if len(path_parts) == 1:
self.logger.debug(f"Client {self.build_log_info(client_addr)} requested to monitor item {path_parts[0]}")
try:
item = self.items.return_item(path)
if item is not None:
item_acl = item.conf.get('acl', None)
if item_acl is None:
item_acl = self.sv_acl
if item_acl != 'deny':
items.append([path, item()])
if self.update_visuitem not in item.get_method_triggers():
item.add_method_trigger(self.update_visuitem)
else:
self.logger.error(f"prepare_monitor: No item '{path}' found (requested by client {self.build_log_info(client_addr)}")
except KeyError as e:
self.logger.warning(f"KeyError: Client {self.build_log_info(client_addr)} requested to monitor item {path_parts[0]} which can not be found")
items.append([path, item()])
if self.update_visuitem not in item.get_method_triggers():
item.add_method_trigger(self.update_visuitem)
else:
newmonitor_items.append(path)
elif len(path_parts) == 2:
self.logger.debug(f"Client {self.build_log_info(client_addr)} requested to monitor item {path_parts[1]} with property {path_parts[0]}")
self.logger.debug(f"Client {self.build_log_info(client_addr)} requested to monitor item {path_parts[0]} with property {path_parts[1]}")
try:
prop = self.items.return_item(path_parts[0]).property
prop_attr = getattr(prop, path_parts[1])
items.append([path, prop_attr])
newmonitor_items.append(path)
if self.update_visuitem not in item.get_method_triggers():
item.add_method_trigger(self.update_visuitem)
else:
newmonitor_items.append(path)
except KeyError as e:
self.logger.warning(f"Property KeyError: Client {self.build_log_info(client_addr)} requested to monitor item {path_parts[0]} with property {path_parts[1]}")
except AttributeError as e:
Expand Down Expand Up @@ -835,8 +844,8 @@ async def update_item(self, item_name, item_value, source):

if len(path_parts) == 2:
self.logger.debug(f"Send update to Client {self.build_log_info(client_addr)} for item {path_parts[0]} with property {path_parts[1]}")
prop = self.items[path_parts[0]]['item'].property
prop_attr = getattr(prop,path_parts[1])
prop = self.items.return_item(path_parts[0]).property
prop_attr = getattr(prop, path_parts[1])
items.append([candidate, prop_attr])
continue

Expand Down
Loading