Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def scan_power_switches(callback=None, **kwargs):
for device in pywemo.discover_devices():
yield terrariumPowerSwitch(md5((terrariumPowerSwitchWeMo.TYPE + device.serialnumber).encode()).hexdigest(),
terrariumPowerSwitchWeMo.TYPE,
device.host,
device.name,
None,
callback)
try:
device = pywemo.discovery.device_from_description(url, None)
except (
requests.exceptions.ConnectionError,
requests.exceptions.Timeout,
) as err:
_LOGGER.error("Unable to access WeMo at %s (%s)", url, err)
continue
if not [d[1] for d in devices if d[1].serialnumber == device.serialnumber]:
devices.append((url, device))
if config.get(DOMAIN, {}).get(CONF_DISCOVERY, DEFAULT_DISCOVERY):
_LOGGER.debug("Scanning network for WeMo devices...")
for device in pywemo.discover_devices():
if not [
d[1] for d in devices if d[1].serialnumber == device.serialnumber
]:
devices.append((setup_url_for_device(device), device))
for url, device in devices:
_LOGGER.debug("Adding WeMo device at %s:%i", device.host, device.port)
discovery_info = {
"model_name": device.model_name,
"serial": device.serialnumber,
"mac_address": device.mac,
"ssdp_description": url,
}
discovery_dispatch(SERVICE_WEMO, discovery_info)
def _scan_once(self):
devices = pywemo.discover_devices()
logging.info('Found %d wemo devices.', len(devices))
for device in devices:
device_exists = device.serialnumber in self._devices
self._devices[device.serialnumber] = device
state = device.get_state()
serialnumber = device.serialnumber
state_changed = state != self._state_cache.get(serialnumber, None)
self._state_cache[serialnumber] = state
details = {
'serial_number': serialnumber,
'model': device.model,
'name': device.name,
continue
try:
device = pywemo.discovery.device_from_description(url, None)
except (requests.exceptions.ConnectionError,
requests.exceptions.Timeout) as err:
_LOGGER.error('Unable to access WeMo at %s (%s)', url, err)
continue
if not [d[1] for d in devices
if d[1].serialnumber == device.serialnumber]:
devices.append((url, device))
if config.get(DOMAIN, {}).get(CONF_DISCOVERY):
_LOGGER.debug("Scanning network for WeMo devices...")
for device in pywemo.discover_devices():
if not [d[1] for d in devices
if d[1].serialnumber == device.serialnumber]:
devices.append((setup_url_for_device(device),
device))
for url, device in devices:
_LOGGER.debug('Adding WeMo device at %s:%i',
device.host, device.port)
discovery_info = {
'device_type': device.__class__.__name__,
'serial': device.serialnumber,
'mac_address': device.mac,
'ssdp_description': url,
}
async def _async_has_devices(hass):
"""Return if there are devices that can be discovered."""
return bool(await hass.async_add_executor_job(pywemo.discover_devices))