I’m working on a custom component to track devices based on their status within Clearpass. It works Ok, but I could use some pointers on how to improve it. One, the tracker seems to be very delayed in scanning and updating hosts. The other issue I have is when get_device_name is called and the name is returned, it’s not updating known_devices.yaml with the name. Also, the get_extra_attributes is not returning the IP of the device, but that is less of a concern.
Thanks in advance!
class CPPMDeviceScanner(DeviceScanner):
def init(self, hass, cppm_host, api_key, scan_interval):
_LOGGER.debug("-------------INIT CALLED--------------")
self._hass = hass
self._cppm_host = cppm_host
self._api_key = api_key
self._scan_int = scan_interval
self.success_init = self.get_cppm_data()
async def async_scan_devices(self):
_LOGGER.debug("------ SCAN DEVICES CALLED. ------------")
self.get_cppm_data()
return [device[‘mac’] for device in self.results]
async def async_get_device_name(self, device):
_LOGGER.debug("------ RESOLVING DEVICE NAME ----")
return [device[‘name’] for device in self.results]
async def async_get_extra_attributes(self, device):
“”“Return the IP of the given device.”""
filter_ip = next((
result[‘ip’] for result in self.results
if result[‘mac’] == device), None)
return {‘ip’: filter_ip}
@Throttle(SCAN_INTERVAL)
def get_cppm_data(self):
------------SNIP---------------
if json_r[‘is_online’] == True:
device = {
‘ip’: json_r[‘ip’],
‘mac’: json_r[‘mac’],
‘name’: json_r[‘device_name’]
}
devices.append(device)
else:
continue
_LOGGER.debug("-----------Update successful!-----------")
self.results = devices
return True