a58382e7630d4bc39f52a1c4f501c922f1421795,homeassistant/components/device_tracker/snmp.py,SnmpScanner,get_snmp_data,#SnmpScanner#,90

Before Change



    def get_snmp_data(self):
         Fetch mac addresses from WAP via SNMP. 
        devices = []


        from pysnmp.entity.rfc3413.oneliner import cmdgen

        oid="1.3.6.1.4.1.14988.1.1.1.2.1.1"
        cmdGen = cmdgen.CommandGenerator()

        errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
            cmdgen.CommunityData( self.community ),
            cmdgen.UdpTransportTarget( ( self.host , 161) ),
            cmdgen.MibVariable( self.baseoid )
        )

        if errorIndication:
            _LOGGER.exception( "SNMPLIB error: {}".format( errorIndication ) )
            return
        else:
            if errorStatus:
                _LOGGER.exception( "SNMP error: {} at {}".format( errorStatus.prettyPrint(), errorIndex and varBindTable[-1][int(errorIndex)-1] or "?" ) )
                return
            else:
                for varBindTableRow in varBindTable:
                    for val in varBindTableRow.values():
                        devices.append( convertMac( val ) )
        return devices

    def convertMac(octect):
        """ Convert a binary mac address to a string """

After Change


            return
        for varBindTableRow in varBindTable:
            for key,val in varBindTableRow:
                mac = binascii.hexlify( val.asOctets() ).decode("utf-8")
                mac = ":".join( [ mac[i:i+2] for i in range( 0, len(mac), 2 ) ] )
                devices[mac] = { "mac" : mac }
        return devices

Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 11

Instances


Project Name: home-assistant/home-assistant
Commit Name: a58382e7630d4bc39f52a1c4f501c922f1421795
Time: 2015-10-07
Author: tom.duijf@gmail.com
File Name: homeassistant/components/device_tracker/snmp.py
Class Name: SnmpScanner
Method Name: get_snmp_data


Project Name: home-assistant/home-assistant
Commit Name: 1d615ea6c3a5f9b3ae6481b827919f04f23c09ce
Time: 2017-08-25
Author: marhje52@kth.se
File Name: homeassistant/components/notify/mysensors.py
Class Name: MySensorsNotificationService
Method Name: send_message


Project Name: home-assistant/home-assistant
Commit Name: 8775c54d29a4adcc11a55c4a37db7da54eccc6e7
Time: 2017-08-25
Author: marhje52@kth.se
File Name: homeassistant/components/notify/mysensors.py
Class Name: MySensorsNotificationService
Method Name: send_message