mirror of
https://github.com/home-assistant/core
synced 2024-09-15 17:29:45 +02:00
Move imports in snmp component (#27939)
* move imports in snmp component * fix: move hlapi import top level
This commit is contained in:
parent
a5ec5b567e
commit
e01562ceea
@ -2,6 +2,8 @@
|
|||||||
import binascii
|
import binascii
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from pysnmp.entity import config as cfg
|
||||||
|
from pysnmp.entity.rfc3413.oneliner import cmdgen
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.device_tracker import (
|
from homeassistant.components.device_tracker import (
|
||||||
@ -45,8 +47,6 @@ class SnmpScanner(DeviceScanner):
|
|||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
"""Initialize the scanner."""
|
"""Initialize the scanner."""
|
||||||
from pysnmp.entity.rfc3413.oneliner import cmdgen
|
|
||||||
from pysnmp.entity import config as cfg
|
|
||||||
|
|
||||||
self.snmp = cmdgen.CommandGenerator()
|
self.snmp = cmdgen.CommandGenerator()
|
||||||
|
|
||||||
|
@ -2,6 +2,17 @@
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
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
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
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):
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||||
"""Set up the SNMP sensor."""
|
"""Set up the SNMP sensor."""
|
||||||
from pysnmp.hlapi.asyncio import (
|
|
||||||
getCmd,
|
|
||||||
CommunityData,
|
|
||||||
SnmpEngine,
|
|
||||||
UdpTransportTarget,
|
|
||||||
ContextData,
|
|
||||||
ObjectType,
|
|
||||||
ObjectIdentity,
|
|
||||||
UsmUserData,
|
|
||||||
)
|
|
||||||
|
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
host = config.get(CONF_HOST)
|
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
|
value_template.hass = hass
|
||||||
|
|
||||||
if version == "3":
|
if version == "3":
|
||||||
import pysnmp.hlapi.asyncio as hlapi
|
|
||||||
|
|
||||||
if not authkey:
|
if not authkey:
|
||||||
authproto = "none"
|
authproto = "none"
|
||||||
@ -194,7 +194,6 @@ class SnmpData:
|
|||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Get the latest data from the remote SNMP capable host."""
|
"""Get the latest data from the remote SNMP capable host."""
|
||||||
from pysnmp.hlapi.asyncio import getCmd, ObjectType, ObjectIdentity
|
|
||||||
|
|
||||||
errindication, errstatus, errindex, restable = await getCmd(
|
errindication, errstatus, errindex, restable = await getCmd(
|
||||||
*self._request_args, ObjectType(ObjectIdentity(self._baseoid))
|
*self._request_args, ObjectType(ObjectIdentity(self._baseoid))
|
||||||
|
@ -1,6 +1,18 @@
|
|||||||
"""Support for SNMP enabled switch."""
|
"""Support for SNMP enabled switch."""
|
||||||
import logging
|
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
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchDevice
|
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchDevice
|
||||||
@ -136,13 +148,6 @@ class SnmpSwitch(SwitchDevice):
|
|||||||
command_payload_off,
|
command_payload_off,
|
||||||
):
|
):
|
||||||
"""Initialize the switch."""
|
"""Initialize the switch."""
|
||||||
from pysnmp.hlapi.asyncio import (
|
|
||||||
CommunityData,
|
|
||||||
ContextData,
|
|
||||||
SnmpEngine,
|
|
||||||
UdpTransportTarget,
|
|
||||||
UsmUserData,
|
|
||||||
)
|
|
||||||
|
|
||||||
self._name = name
|
self._name = name
|
||||||
self._baseoid = baseoid
|
self._baseoid = baseoid
|
||||||
@ -157,7 +162,6 @@ class SnmpSwitch(SwitchDevice):
|
|||||||
self._payload_off = payload_off
|
self._payload_off = payload_off
|
||||||
|
|
||||||
if version == "3":
|
if version == "3":
|
||||||
import pysnmp.hlapi.asyncio as hlapi
|
|
||||||
|
|
||||||
if not authkey:
|
if not authkey:
|
||||||
authproto = "none"
|
authproto = "none"
|
||||||
@ -194,7 +198,6 @@ class SnmpSwitch(SwitchDevice):
|
|||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Update the state."""
|
"""Update the state."""
|
||||||
from pysnmp.hlapi.asyncio import getCmd, ObjectType, ObjectIdentity
|
|
||||||
|
|
||||||
errindication, errstatus, errindex, restable = await getCmd(
|
errindication, errstatus, errindex, restable = await getCmd(
|
||||||
*self._request_args, ObjectType(ObjectIdentity(self._baseoid))
|
*self._request_args, ObjectType(ObjectIdentity(self._baseoid))
|
||||||
@ -228,7 +231,6 @@ class SnmpSwitch(SwitchDevice):
|
|||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
async def _set(self, value):
|
async def _set(self, value):
|
||||||
from pysnmp.hlapi.asyncio import setCmd, ObjectType, ObjectIdentity
|
|
||||||
|
|
||||||
await setCmd(
|
await setCmd(
|
||||||
*self._request_args, ObjectType(ObjectIdentity(self._commandoid), value)
|
*self._request_args, ObjectType(ObjectIdentity(self._commandoid), value)
|
||||||
|
Loading…
Reference in New Issue
Block a user