From 5503c12cfd1460a3e13ad0a9d53879c4202622cb Mon Sep 17 00:00:00 2001 From: Tom Duijf Date: Wed, 11 Nov 2015 21:54:33 +0000 Subject: [PATCH] Fixes memory consumption issue --- .../components/device_tracker/snmp.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/device_tracker/snmp.py b/homeassistant/components/device_tracker/snmp.py index bf2d7e0a51c..868f701673a 100644 --- a/homeassistant/components/device_tracker/snmp.py +++ b/homeassistant/components/device_tracker/snmp.py @@ -45,9 +45,12 @@ class SnmpScanner(object): This class queries any SNMP capable Acces Point for connected devices. """ def __init__(self, config): - self.host = config[CONF_HOST] - self.community = config[CONF_COMMUNITY] - self.baseoid = config[CONF_BASEOID] + from pysnmp.entity.rfc3413.oneliner import cmdgen + self.snmp = cmdgen.CommandGenerator() + + self.host = cmdgen.UdpTransportTarget((config[CONF_HOST], 161)) + self.community = cmdgen.CommunityData(config[CONF_COMMUNITY]) + self.baseoid = cmdgen.MibVariable(config[CONF_BASEOID]) self.lock = threading.Lock() @@ -91,16 +94,11 @@ class SnmpScanner(object): def get_snmp_data(self): """ Fetch mac addresses from WAP via SNMP. """ - from pysnmp.entity.rfc3413.oneliner import cmdgen devices = [] - snmp = cmdgen.CommandGenerator() - errindication, errstatus, errindex, restable = snmp.nextCmd( - cmdgen.CommunityData(self.community), - cmdgen.UdpTransportTarget((self.host, 161)), - cmdgen.MibVariable(self.baseoid) - ) + errindication, errstatus, errindex, restable = self.snmp.nextCmd( + self.community, self.host, self.baseoid) if errindication: _LOGGER.error("SNMPLIB error: %s", errindication)