Skip to content
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
13 changes: 12 additions & 1 deletion enocean/protocol/eep.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class EEP(object):
def __init__(self):
self.init_ok = False
self.telegrams = {}
# Shortcut cache for set_values
self._shortcuts = {}

eep_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'EEP.xml')
try:
Expand Down Expand Up @@ -224,9 +226,18 @@ def set_values(self, profile, data, status, properties):
if not self.init_ok or profile is None:
return data, status

# Get shortcuts for this profile from cache, or index them if not present
profile_id = id(profile)
if profile_id not in self._shortcuts:
self._shortcuts[profile_id] = {
el.get('shortcut'): el
for el in profile.iter()
if el.get('shortcut')
}

for shortcut, value in properties.items():
# find the given property from EEP
target = profile.find('.//*[@shortcut="%s"]' % shortcut)
target = self._shortcuts[profile_id].get(shortcut)
if target is None:
# TODO: Should we raise an error?
self.logger.warning('Cannot find data description for shortcut %s', shortcut)
Expand Down
Loading