Move imports in snmp component (#27939)

* move imports in snmp component

* fix: move hlapi import top level
This commit is contained in:
Michał Mrozek authored and Fabian Affolter committed 2019-10-20 10:06:32 +02:00
1 parent a5ec5b567e
commit e01562ceea
3 files changed
+25 -24

No files matched your search

+12 -10
View File
@@ -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)