diff --git a/brother/__init__.py b/brother/__init__.py index f8ea9ae..f456cce 100644 --- a/brother/__init__.py +++ b/brother/__init__.py @@ -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 ( @@ -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(), @@ -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 @@ -291,7 +291,7 @@ 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.""" @@ -299,7 +299,7 @@ async def _get_data(self) -> dict[str, Any]: 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: diff --git a/brother/utils.py b/brother/utils.py index 4111df4..3364728 100644 --- a/brother/utils.py +++ b/brother/utils.py @@ -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: @@ -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 diff --git a/requirements.txt b/requirements.txt index 8fdb94b..abbd316 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ dacite>=1.7.0 -pysnmp>=6.2.6,<7.0 +pysnmp>=7.1.6