diff --git a/homeassistant/components/snmp/device_tracker.py b/homeassistant/components/snmp/device_tracker.py index a628c426e0f..eafae9537e5 100644 --- a/homeassistant/components/snmp/device_tracker.py +++ b/homeassistant/components/snmp/device_tracker.py @@ -2,6 +2,8 @@ import binascii import logging +from pysnmp.entity import config as cfg +from pysnmp.entity.rfc3413.oneliner import cmdgen import voluptuous as vol from homeassistant.components.device_tracker import ( @@ -45,8 +47,6 @@ class SnmpScanner(DeviceScanner): def __init__(self, config): """Initialize the scanner.""" - from pysnmp.entity.rfc3413.oneliner import cmdgen - from pysnmp.entity import config as cfg self.snmp = cmdgen.CommandGenerator() diff --git a/homeassistant/components/snmp/sensor.py b/homeassistant/components/snmp/sensor.py index 5e6b5ed1f28..b369ec83c58 100644 --- a/homeassistant/components/snmp/sensor.py +++ b/homeassistant/components/snmp/sensor.py @@ -2,6 +2,17 @@ from datetime import timedelta import logging +import pysnmp.hlapi.asyncio as hlapi +from pysnmp.hlapi.asyncio import ( + CommunityData, + ContextData, + ObjectIdentity, + ObjectType, + SnmpEngine, + UdpTransportTarget, + UsmUserData, + getCmd, +) import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA @@ -70,16 +81,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the SNMP sensor.""" - from pysnmp.hlapi.asyncio import ( - getCmd, - CommunityData, - SnmpEngine, - UdpTransportTarget, - ContextData, - ObjectType, - ObjectIdentity, - UsmUserData, - ) name = config.get(CONF_NAME) host = config.get(CONF_HOST) @@ -101,7 +102,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= value_template.hass = hass if version == "3": - import pysnmp.hlapi.asyncio as hlapi if not authkey: authproto = "none" @@ -194,7 +194,6 @@ class SnmpData: async def async_update(self): """Get the latest data from the remote SNMP capable host.""" - from pysnmp.hlapi.asyncio import getCmd, ObjectType, ObjectIdentity errindication, errstatus, errindex, restable = await getCmd( *self._request_args, ObjectType(ObjectIdentity(self._baseoid)) diff --git a/homeassistant/components/snmp/switch.py b/homeassistant/components/snmp/switch.py index 204e98cca83..aac43208a1f 100644 --- a/homeassistant/components/snmp/switch.py +++ b/homeassistant/components/snmp/switch.py @@ -1,6 +1,18 @@ """Support for SNMP enabled switch.""" import logging +import pysnmp.hlapi.asyncio as hlapi +from pysnmp.hlapi.asyncio import ( + CommunityData, + ContextData, + ObjectIdentity, + ObjectType, + SnmpEngine, + UdpTransportTarget, + UsmUserData, + getCmd, + setCmd, +) import voluptuous as vol from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchDevice @@ -136,13 +148,6 @@ class SnmpSwitch(SwitchDevice): command_payload_off, ): """Initialize the switch.""" - from pysnmp.hlapi.asyncio import ( - CommunityData, - ContextData, - SnmpEngine, - UdpTransportTarget, - UsmUserData, - ) self._name = name self._baseoid = baseoid @@ -157,7 +162,6 @@ class SnmpSwitch(SwitchDevice): self._payload_off = payload_off if version == "3": - import pysnmp.hlapi.asyncio as hlapi if not authkey: authproto = "none" @@ -194,7 +198,6 @@ class SnmpSwitch(SwitchDevice): async def async_update(self): """Update the state.""" - from pysnmp.hlapi.asyncio import getCmd, ObjectType, ObjectIdentity errindication, errstatus, errindex, restable = await getCmd( *self._request_args, ObjectType(ObjectIdentity(self._baseoid)) @@ -228,7 +231,6 @@ class SnmpSwitch(SwitchDevice): return self._state async def _set(self, value): - from pysnmp.hlapi.asyncio import setCmd, ObjectType, ObjectIdentity await setCmd( *self._request_args, ObjectType(ObjectIdentity(self._commandoid), value)