From 213a1fe4ba26984be3bc1aff8392991b0cfb79a3 Mon Sep 17 00:00:00 2001 From: Tom Duijf Date: Thu, 8 Oct 2015 08:00:30 +0000 Subject: [PATCH] Various fixes, CI validation --- .coveragerc | 1 - .../components/device_tracker/snmp.py | 34 ++++++++++++------- homeassistant/const.py | 2 -- requirements_all.txt | 2 +- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/.coveragerc b/.coveragerc index d9b4a29a1b5..433a43bea10 100644 --- a/.coveragerc +++ b/.coveragerc @@ -40,7 +40,6 @@ omit = homeassistant/components/device_tracker/tomato.py homeassistant/components/device_tracker/tplink.py homeassistant/components/device_tracker/snmp.py - homeassistant/components/discovery.py homeassistant/components/downloader.py homeassistant/components/keyboard.py diff --git a/homeassistant/components/device_tracker/snmp.py b/homeassistant/components/device_tracker/snmp.py index 9113a1ab98d..6d8f5113df0 100644 --- a/homeassistant/components/device_tracker/snmp.py +++ b/homeassistant/components/device_tracker/snmp.py @@ -36,9 +36,8 @@ import logging from datetime import timedelta import threading import binascii -from pysnmp.entity.rfc3413.oneliner import cmdgen -from homeassistant.const import CONF_HOST, CONF_COMMUNITY, CONF_BASEOID +from homeassistant.const import CONF_HOST from homeassistant.helpers import validate_config from homeassistant.util import Throttle from homeassistant.components.device_tracker import DOMAIN @@ -47,7 +46,10 @@ from homeassistant.components.device_tracker import DOMAIN MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10) _LOGGER = logging.getLogger(__name__) -REQUIREMENTS = ['pysnmp<=4.2.5'] +REQUIREMENTS = ['pysnmp==4.2.5'] + +CONF_COMMUNITY = "community" +CONF_BASEOID = "baseoid" # pylint: disable=unused-argument @@ -90,6 +92,7 @@ class SnmpScanner(object): def get_device_name(self, device): """ Returns the name of the given device or None if we don't know. """ + # We have no names return None @Throttle(MIN_TIME_BETWEEN_SCANS) @@ -111,25 +114,30 @@ class SnmpScanner(object): def get_snmp_data(self): """ Fetch mac addresses from WAP via SNMP. """ + from pysnmp.entity.rfc3413.oneliner import cmdgen devices = [] - cmdGen = cmdgen.CommandGenerator() - errIndication, errStatus, errIndex, varBindTable = cmdGen.nextCmd( + snmp = cmdgen.CommandGenerator() + errindication, errstatus, errindex, restable = snmp.nextCmd( cmdgen.CommunityData(self.community), cmdgen.UdpTransportTarget((self.host, 161)), cmdgen.MibVariable(self.baseoid) ) - if errIndication: - _LOGGER.exception("SNMPLIB error: {}".format(errIndication)) + + if errindication: + _LOGGER.error("SNMPLIB error: {}".format(errindication)) return - if errStatus: - _LOGGER.exception("SNMP error: {} at {}".format( - errStatus.prettyPrint(), - errIndex and varBindTable[-1][int(errIndex)-1] or '?')) + if errstatus: + err = "SNMP error: {} at {}" + _LOGGER.error(err.format(errstatus.prettyPrint(), + errindex and + restable[-1][int(errindex)-1] + or '?')) return - for varBindTableRow in varBindTable: - for _, val in varBindTableRow: + + for resrow in restable: + for _, val in resrow: mac = binascii.hexlify(val.asOctets()).decode('utf-8') mac = ':'.join([mac[i:i+2] for i in range(0, len(mac), 2)]) devices.append({'mac': mac}) diff --git a/homeassistant/const.py b/homeassistant/const.py index 53ccd3c67db..2d272ca3a0b 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -24,8 +24,6 @@ CONF_USERNAME = "username" CONF_PASSWORD = "password" CONF_API_KEY = "api_key" CONF_ACCESS_TOKEN = "access_token" -CONF_COMMUNITY = "community" -CONF_BASEOID = "baseoid" # #### EVENTS #### EVENT_HOMEASSISTANT_START = "homeassistant_start" diff --git a/requirements_all.txt b/requirements_all.txt index 1c59b62fabd..7e3a3acc458 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -139,5 +139,5 @@ SoCo==0.11.1 https://github.com/adrienbrault/python-plexapi/archive/df2d0847e801d6d5cda920326d693cf75f304f1a.zip#python-plexapi==1.0.2 # python-pysnmp (device_tracker.snmp) -pysnmp>=4.2.5 +pysnmp==4.2.5