Add support for Cisco Mobility Express (#21531)
* Move cisco me to new layout * Add docstring * Move items out of init method and pass the controller instance to the scanner in get_scanner * Update homeassistant/components/cisco_mobility_express/device_tracker.py Co-Authored-By: fbradyirl <fbradyirl@users.noreply.github.com> * Update homeassistant/components/cisco_mobility_express/device_tracker.py Co-Authored-By: fbradyirl <fbradyirl@users.noreply.github.com> * Update homeassistant/components/cisco_mobility_express/device_tracker.py Co-Authored-By: fbradyirl <fbradyirl@users.noreply.github.com> * Update homeassistant/components/cisco_mobility_express/device_tracker.py Co-Authored-By: fbradyirl <fbradyirl@users.noreply.github.com> * Fix build error * Cleanup based on comments.
This commit is contained in:
parent
31a4187cc0
commit
0f189809a9
4 changed files with 88 additions and 0 deletions
|
@ -68,6 +68,7 @@ omit =
|
|||
homeassistant/components/camera/xiaomi.py
|
||||
homeassistant/components/camera/yi.py
|
||||
homeassistant/components/cast/*
|
||||
homeassistant/components/cisco_mobility_express/device_tracker.py
|
||||
homeassistant/components/climate/coolmaster.py
|
||||
homeassistant/components/climate/ephember.py
|
||||
homeassistant/components/climate/eq3btsmart.py
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
"""Component to embed Cisco Mobility Express."""
|
|
@ -0,0 +1,83 @@
|
|||
"""Support for Cisco Mobility Express."""
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.device_tracker import (
|
||||
DOMAIN, PLATFORM_SCHEMA, DeviceScanner)
|
||||
from homeassistant.const import (
|
||||
CONF_HOST, CONF_USERNAME, CONF_PASSWORD, CONF_SSL, CONF_VERIFY_SSL)
|
||||
|
||||
|
||||
REQUIREMENTS = ['ciscomobilityexpress==0.1.2']
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_SSL = False
|
||||
DEFAULT_VERIFY_SSL = True
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean,
|
||||
vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL): cv.boolean,
|
||||
})
|
||||
|
||||
|
||||
def get_scanner(hass, config):
|
||||
"""Validate the configuration and return a Cisco ME scanner."""
|
||||
from ciscomobilityexpress.ciscome import CiscoMobilityExpress
|
||||
config = config[DOMAIN]
|
||||
|
||||
controller = CiscoMobilityExpress(
|
||||
config[CONF_HOST],
|
||||
config[CONF_USERNAME],
|
||||
config[CONF_PASSWORD],
|
||||
config.get(CONF_SSL),
|
||||
config.get(CONF_VERIFY_SSL))
|
||||
if not controller.is_logged_in():
|
||||
return None
|
||||
return CiscoMEDeviceScanner(controller)
|
||||
|
||||
|
||||
class CiscoMEDeviceScanner(DeviceScanner):
|
||||
"""This class scans for devices associated to a Cisco ME controller."""
|
||||
|
||||
def __init__(self, controller):
|
||||
"""Initialize the scanner."""
|
||||
self.controller = controller
|
||||
self.last_results = {}
|
||||
|
||||
def scan_devices(self):
|
||||
"""Scan for new devices and return a list with found device IDs."""
|
||||
self._update_info()
|
||||
|
||||
return [device.macaddr for device in self.last_results]
|
||||
|
||||
def get_device_name(self, device):
|
||||
"""Return the name of the given device or None if we don't know."""
|
||||
name = next((
|
||||
result.clId for result in self.last_results
|
||||
if result.macaddr == device), None)
|
||||
return name
|
||||
|
||||
def get_extra_attributes(self, device):
|
||||
"""
|
||||
Get extra attributes of a device.
|
||||
|
||||
Some known extra attributes that may be returned in the device tuple
|
||||
include SSID, PT (eg 802.11ac), devtype (eg iPhone 7) among others.
|
||||
"""
|
||||
device = next((
|
||||
result for result in self.last_results
|
||||
if result.macaddr == device), None)
|
||||
return device._asdict()
|
||||
|
||||
def _update_info(self):
|
||||
"""Check the Cisco ME controller for devices."""
|
||||
self.last_results = self.controller.get_associated_devices()
|
||||
_LOGGER.debug("Cisco Mobility Express controller returned:"
|
||||
" %s", self.last_results)
|
|
@ -265,6 +265,9 @@ buienradar==0.91
|
|||
# homeassistant.components.calendar.caldav
|
||||
caldav==0.5.0
|
||||
|
||||
# homeassistant.components.cisco_mobility_express.device_tracker
|
||||
ciscomobilityexpress==0.1.2
|
||||
|
||||
# homeassistant.components.notify.ciscospark
|
||||
ciscosparkapi==0.4.2
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue