Skip to content

Commit

Permalink
Merge pull request #12 from jaroschek/feature/missing-oids
Browse files Browse the repository at this point in the history
Ignore missing OIDs and retry
  • Loading branch information
jaroschek authored Sep 18, 2024
2 parents 524ee3b + c29bf85 commit 7cf017a
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions custom_components/eaton_epdu/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,33 @@ def construct_object_types(list_of_oids):

async def get(self, oids) -> dict:
"""Get data for given OIDs in a single call."""
_LOGGER.debug("Get OID(s) %s", oids)
result = []
error_indication, error_status, error_index, var_binds = await hlapi.getCmd(
self._snmpEngine,
self._credentials,
self._target,
hlapi.ContextData(),
*__class__.construct_object_types(oids),
)
while len(oids):
_LOGGER.debug("Get OID(s) %s", oids)

error_indication, error_status, error_index, var_binds = await hlapi.getCmd(
self._snmpEngine,
self._credentials,
self._target,
hlapi.ContextData(),
*__class__.construct_object_types(oids),
)

if error_index:
_LOGGER.debug("Remove error index %d", error_index - 1)
oids.pop(error_index - 1)
continue

if error_indication or error_status:
raise RuntimeError(
f"Got SNMP error: {error_indication} {error_status} {error_index}"
)

if not error_indication and not error_status:
items = {}
for var_bind in var_binds:
items[str(var_bind[0])] = __class__.cast(var_bind[1])
result.append(items)
else:
raise RuntimeError(
"Got SNMP error: {error_indication} {error_status} {error_index}"
)
return items

return result[0]
return []

async def get_bulk(
self,
Expand Down

0 comments on commit 7cf017a

Please sign in to comment.