Skip to content

Commit

Permalink
Bump pysnmp to version 7.1.6 or newer (#505)
Browse files Browse the repository at this point in the history
* Bump pysnmp to version 7.1.6 or newer

* Revert version
  • Loading branch information
bieniu authored Nov 5, 2024
1 parent 2cac8ac commit fe594c3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
14 changes: 7 additions & 7 deletions brother/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

from dacite import from_dict
from pysnmp.error import PySnmpError
from pysnmp.hlapi.asyncio import (
from pysnmp.hlapi.v3arch.asyncio import (
CommunityData,
ContextData,
ObjectIdentity,
SnmpEngine,
UdpTransportTarget,
getCmd,
get_cmd,
)
from pysnmp.hlapi.asyncio.cmdgen import lcd
from pysnmp.hlapi.v3arch.asyncio.cmdgen import LCD
from pysnmp.smi.rfc1902 import ObjectType

from .const import (
Expand Down Expand Up @@ -142,7 +142,7 @@ async def initialize(self) -> None:
self._request_args = (
self._snmp_engine,
CommunityData("public", mpModel=0),
UdpTransportTarget(
await UdpTransportTarget.create(
(self._host, self._port), timeout=DEFAULT_TIMEOUT, retries=RETRIES
),
ContextData(),
Expand All @@ -152,7 +152,7 @@ async def initialize(self) -> None:

while True:
async with timeout(DEFAULT_TIMEOUT * RETRIES):
_, errstatus, errindex, _ = await getCmd(*self._request_args, *oids)
_, errstatus, errindex, _ = await get_cmd(*self._request_args, *oids)

if str(errstatus) == "noSuchName":
# 5 and 8 are indexes from OIDS consts, model and serial are obligatory
Expand Down Expand Up @@ -291,15 +291,15 @@ async def async_update(self) -> BrotherSensors:
def shutdown(self) -> None:
"""Unconfigure SNMP engine."""
if self._snmp_engine:
lcd.unconfigure(self._snmp_engine, None)
LCD.unconfigure(self._snmp_engine, None)

async def _get_data(self) -> dict[str, Any]:
"""Retrieve data from printer."""
raw_data: dict[str, str | list[str]] = {}
raw_status: bytes | None = None

try:
errindication, errstatus, errindex, restable = await getCmd(
errindication, errstatus, errindex, restable = await get_cmd(
*self._request_args, *self._oids
)
except PySnmpError as err:
Expand Down
16 changes: 7 additions & 9 deletions brother/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import asyncio

from pysnmp.hlapi.asyncio import SnmpEngine
from pysnmp.hlapi.asyncio.cmdgen import vbProcessor
from pysnmp.smi.builder import MibBuilder
from pysnmp.hlapi.v3arch.asyncio import SnmpEngine
from pysnmp.hlapi.varbinds import MibViewControllerManager


async def async_get_snmp_engine() -> SnmpEngine:
Expand All @@ -16,11 +15,10 @@ async def async_get_snmp_engine() -> SnmpEngine:
def _get_snmp_engine() -> SnmpEngine:
"""Return an instance of SnmpEngine."""
engine = SnmpEngine()
mib_controller = vbProcessor.getMibViewController(engine)
# Actually load the MIBs from disk so we do
# not do it in the event loop
builder: MibBuilder = mib_controller.mibBuilder
if "PYSNMP-MIB" not in builder.mibSymbols:
builder.loadModules()
# Actually load the MIBs from disk so we do not do it in the event loop
mib_view_controller = MibViewControllerManager.get_mib_view_controller(engine.cache)
if "PYSNMP-MIB" not in mib_view_controller.mibBuilder.mibSymbols:
mib_view_controller.mibBuilder.load_modules()
engine.cache["mibViewController"] = mib_view_controller

return engine
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dacite>=1.7.0
pysnmp>=6.2.6,<7.0
pysnmp>=7.1.6

0 comments on commit fe594c3

Please sign in to comment.