Add ClearPass Policy Manger device tracker (#21673)
* Adding ClearPass Policy Manger device tracker. Amending author * Cleaned redundant code * Updated .coveragerc * Updated requirements_all.txt * Implemented suggested changes partially. * Implemented more suggested changes. * Hound was unhappy * Implement further suggested changes. * Make Hound happy. * Satisfy Travic CI * Satisfy Travis CI #2 * Hound barking * pylint else: return * Implemented suggested changes minus AccessToken * Removed access token logging * Removed throttle import * Removed period from debug string * Make travis happy :( * Moved source to new component structure. * Forgot to rename source.pull/21993/head
parent
f4f0d363ca
commit
896075fa1c
|
@ -110,6 +110,7 @@ omit =
|
|||
homeassistant/components/device_tracker/bt_home_hub_5.py
|
||||
homeassistant/components/device_tracker/bt_smarthub.py
|
||||
homeassistant/components/device_tracker/cisco_ios.py
|
||||
homeassistant/components/cppm_tracker/device_tracker.py
|
||||
homeassistant/components/device_tracker/ddwrt.py
|
||||
homeassistant/components/device_tracker/fritz.py
|
||||
homeassistant/components/device_tracker/google_maps.py
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
"""Add support for ClearPass Policy Manager."""
|
|
@ -0,0 +1,85 @@
|
|||
"""
|
||||
Support for ClearPass Policy Manager.
|
||||
|
||||
Allows tracking devices with CPPM.
|
||||
"""
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
|
||||
import voluptuous as vol
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.device_tracker import (
|
||||
PLATFORM_SCHEMA, DeviceScanner, DOMAIN
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_HOST, CONF_API_KEY
|
||||
)
|
||||
|
||||
REQUIREMENTS = ['clearpasspy==1.0.2']
|
||||
|
||||
SCAN_INTERVAL = timedelta(seconds=120)
|
||||
|
||||
CLIENT_ID = 'client_id'
|
||||
|
||||
GRANT_TYPE = 'client_credentials'
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Required(CLIENT_ID): cv.string,
|
||||
vol.Required(CONF_API_KEY): cv.string,
|
||||
})
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_scanner(hass, config):
|
||||
"""Initialize Scanner."""
|
||||
from clearpasspy import ClearPass
|
||||
data = {
|
||||
'server': config[DOMAIN][CONF_HOST],
|
||||
'grant_type': GRANT_TYPE,
|
||||
'secret': config[DOMAIN][CONF_API_KEY],
|
||||
'client': config[DOMAIN][CLIENT_ID]
|
||||
}
|
||||
cppm = ClearPass(data)
|
||||
if cppm.access_token is None:
|
||||
return None
|
||||
_LOGGER.debug("Successfully received Access Token")
|
||||
return CPPMDeviceScanner(cppm)
|
||||
|
||||
|
||||
class CPPMDeviceScanner(DeviceScanner):
|
||||
"""Initialize class."""
|
||||
|
||||
def __init__(self, cppm):
|
||||
"""Initialize class."""
|
||||
self._cppm = cppm
|
||||
self.results = None
|
||||
|
||||
def scan_devices(self):
|
||||
"""Initialize scanner."""
|
||||
self.get_cppm_data()
|
||||
return [device['mac'] for device in self.results]
|
||||
|
||||
def get_device_name(self, device):
|
||||
"""Retrieve device name."""
|
||||
name = next((
|
||||
result['name'] for result in self.results
|
||||
if result['mac'] == device), None)
|
||||
return name
|
||||
|
||||
def get_cppm_data(self):
|
||||
"""Retrieve data from Aruba Clearpass and return parsed result."""
|
||||
endpoints = self._cppm.get_endpoints(100)['_embedded']['items']
|
||||
devices = []
|
||||
for item in endpoints:
|
||||
if self._cppm.online_status(item['mac_address']):
|
||||
device = {
|
||||
'mac': item['mac_address'],
|
||||
'name': item['mac_address']
|
||||
}
|
||||
devices.append(device)
|
||||
else:
|
||||
continue
|
||||
_LOGGER.debug("Devices: %s", devices)
|
||||
self.results = devices
|
|
@ -271,6 +271,9 @@ ciscomobilityexpress==0.1.2
|
|||
# homeassistant.components.notify.ciscospark
|
||||
ciscosparkapi==0.4.2
|
||||
|
||||
# homeassistant.components.cppm_tracker.device_tracker
|
||||
clearpasspy==1.0.2
|
||||
|
||||
# homeassistant.components.sensor.co2signal
|
||||
co2signal==0.4.2
|
||||
|
||||
|
|
Loading…
Reference in New Issue