Skip to content
Closed
Show file tree
Hide file tree
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
30 changes: 30 additions & 0 deletions luxtronik/data_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,34 @@ def __iter__(self):

@property
def data(self):
"""
Return the internal `LuxtronikFieldsDictionary`.
Please check its documentation.
"""
return self._data

def __getitem__(self, def_name_or_idx):
"""
Array-style access to method `get`.
Please check its documentation.
"""
return self.get(def_name_or_idx)

def __setitem__(self, def_name_or_idx, value):
"""
Array-style access to method `set`.
Please check its documentation.
"""
return self.set(def_name_or_idx, value)


def __contains__(self, def_field_name_or_idx):
"""
Forward the `LuxtronikFieldsDictionary.__contains__` method.
Please check its documentation.
"""
return def_field_name_or_idx in self._data

def _name_lookup(self, name):
"""
Try to find the index using the given field name.
Expand Down Expand Up @@ -94,3 +120,7 @@ def get(self, target):
"""Get entry by id or name."""
entry = self._lookup(target)
return entry

def set(self, target, value):
"TODO: Placeholder for future changes"
pass
20 changes: 0 additions & 20 deletions luxtronik/shi/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,32 +143,12 @@ def empty(cls, version=LUXTRONIK_LATEST_SHI_VERSION, safe=True):
obj._init_instance(version, safe)
return obj

def __getitem__(self, def_name_or_idx):
return self.get(def_name_or_idx)

def __setitem__(self, def_name_or_idx, value):
return self.set(def_name_or_idx, value)

def __len__(self):
return len(self._data.pairs())

def __iter__(self):
return iter([definition for definition, _ in self._data.pairs()])

def __contains__(self, def_field_name_or_idx):
"""
Check whether the data vector contains a name, index,
or definition matching an added field, or the field itself.

Args:
def_field_name_or_idx (LuxtronikDefinition | Base | str | int):
Definition object, field object, field name or register index.

Returns:
True if the searched element was found, otherwise False.
"""
return def_field_name_or_idx in self._data


# properties and access methods ###############################################

Expand Down