1
mirror of https://github.com/home-assistant/core synced 2024-09-03 08:14:07 +02:00

Move imports in snmp component (#27939)

* move imports in snmp component

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

View File

@ -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()

View File

@ -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))

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)