def setup_platform(hass, config, add_devices_callback, discovery_info=None): """ Find and return WeMo switches. """ import pywemo import pywemo.discovery as discovery global _WEMO_SUBSCRIPTION_REGISTRY if _WEMO_SUBSCRIPTION_REGISTRY is None: _WEMO_SUBSCRIPTION_REGISTRY = pywemo.SubscriptionRegistry() _WEMO_SUBSCRIPTION_REGISTRY.start() def stop_wemo(event): """ Shutdown Wemo subscriptions and subscription thread on exit""" _LOGGER.info("Shutting down subscriptions.") _WEMO_SUBSCRIPTION_REGISTRY.stop() hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_wemo) if discovery_info is not None: location = discovery_info[2] mac = discovery_info[3] device = discovery.device_from_description(location, mac) if device: add_devices_callback([WemoSwitch(device)]) return _LOGGER.info("Scanning for WeMo devices.") switches = pywemo.discover_devices() # Filter out the switches and wrap in WemoSwitch object add_devices_callback([ WemoSwitch(switch) for switch in switches if isinstance(switch, pywemo.Switch) ])
def setup_platform(hass, config, add_devices_callback, discovery_info=None): """ Find and return WeMo switches. """ import pywemo import pywemo.discovery as discovery global _WEMO_SUBSCRIPTION_REGISTRY if _WEMO_SUBSCRIPTION_REGISTRY is None: _WEMO_SUBSCRIPTION_REGISTRY = pywemo.SubscriptionRegistry() _WEMO_SUBSCRIPTION_REGISTRY.start() def stop_wemo(event): """ Shutdown Wemo subscriptions and subscription thread on exit""" _LOGGER.info("Shutting down subscriptions.") _WEMO_SUBSCRIPTION_REGISTRY.stop() hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_wemo) if discovery_info is not None: location = discovery_info[2] mac = discovery_info[3] device = discovery.device_from_description(location, mac) if device: add_devices_callback([WemoSwitch(device)]) return _LOGGER.info("Scanning for WeMo devices.") switches = pywemo.discover_devices() # Filter out the switches and wrap in WemoSwitch object add_devices_callback( [WemoSwitch(switch) for switch in switches if isinstance(switch, pywemo.Switch)])
def setup_platform(hass, config, add_devices_callback, discovery_info=None): """Set up discovered WeMo switches.""" import pywemo.discovery as discovery if discovery_info is not None: location = discovery_info['ssdp_description'] mac = discovery_info['mac_address'] device = discovery.device_from_description(location, mac) if device: add_devices_callback([WemoSwitch(device)])
def setup_platform(hass, config, add_devices_callback, discovery_info=None): """Set up discovered WeMo switches.""" from pywemo import discovery if discovery_info is not None: location = discovery_info['ssdp_description'] mac = discovery_info['mac_address'] device = discovery.device_from_description(location, mac) if device: add_devices_callback([WemoSwitch(device)])
def setup_platform(hass, config, add_devices_callback, discovery_info=None): """Register discovered WeMo binary sensors.""" from pywemo import discovery if discovery_info is not None: location = discovery_info['ssdp_description'] mac = discovery_info['mac_address'] device = discovery.device_from_description(location, mac) if device: add_devices_callback([WemoBinarySensor(hass, device)])
def setup_platform(hass, config, add_devices_callback, discovery_info=None): """Register discovered WeMo binary sensors.""" import pywemo.discovery as discovery if discovery_info is not None: location = discovery_info['ssdp_description'] mac = discovery_info['mac_address'] device = discovery.device_from_description(location, mac) if device: add_devices_callback([WemoBinarySensor(device)])
def setup_platform(hass, config, add_devices_callback, discovery_info=None): """Probe WeMo bridges and register connected lights.""" import pywemo.discovery as discovery if discovery_info is not None: location = discovery_info[2] mac = discovery_info[3] device = discovery.device_from_description(location, mac) if device: setup_bridge(device, add_devices_callback)
def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the WeMo bridges and register connected lights.""" import pywemo.discovery as discovery if discovery_info is not None: location = discovery_info['ssdp_description'] mac = discovery_info['mac_address'] device = discovery.device_from_description(location, mac) if device: setup_bridge(device, add_devices)
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up discovered WeMo humidifiers.""" from pywemo import discovery if DATA_KEY not in hass.data: hass.data[DATA_KEY] = {} if discovery_info is None: return location = discovery_info["ssdp_description"] mac = discovery_info["mac_address"] try: device = WemoHumidifier( discovery.device_from_description(location, mac)) except (requests.exceptions.ConnectionError, requests.exceptions.Timeout) as err: _LOGGER.error("Unable to access %s (%s)", location, err) raise PlatformNotReady hass.data[DATA_KEY][device.entity_id] = device add_entities([device]) def service_handle(service): """Handle the WeMo humidifier services.""" entity_ids = service.data.get(ATTR_ENTITY_ID) humidifiers = [ device for device in hass.data[DATA_KEY].values() if device.entity_id in entity_ids ] if service.service == SERVICE_SET_HUMIDITY: target_humidity = service.data.get(ATTR_TARGET_HUMIDITY) for humidifier in humidifiers: humidifier.set_humidity(target_humidity) elif service.service == SERVICE_RESET_FILTER_LIFE: for humidifier in humidifiers: humidifier.reset_filter_life() # Register service(s) hass.services.register(DOMAIN, SERVICE_SET_HUMIDITY, service_handle, schema=SET_HUMIDITY_SCHEMA) hass.services.register( DOMAIN, SERVICE_RESET_FILTER_LIFE, service_handle, schema=RESET_FILTER_LIFE_SCHEMA, )
def setup_platform(hass, config, add_devices_callback, discovery_info=None): """Register discovered WeMo binary sensors.""" import pywemo.discovery as discovery if discovery_info is not None: location = discovery_info[2] mac = discovery_info[3] device = discovery.device_from_description(location, mac) if device: add_devices_callback([WemoBinarySensor(device)])
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup WeMo bridges and register connected lights.""" import pywemo.discovery as discovery if discovery_info is not None: location = discovery_info[2] mac = discovery_info[3] device = discovery.device_from_description(location, mac) if device: setup_bridge(device, add_devices)
def setup_platform(hass, config, add_devices_callback, discovery_info=None): """Setup discovered WeMo switches.""" import pywemo.discovery as discovery if discovery_info is not None: location = discovery_info[2] mac = discovery_info[3] device = discovery.device_from_description(location, mac) if device: add_devices_callback([WemoSwitch(device)])
def setup_platform(hass, config, add_devices, discovery_info=None): """Set up discovered WeMo switches.""" import pywemo.discovery as discovery if discovery_info is not None: location = discovery_info['ssdp_description'] mac = discovery_info['mac_address'] device = discovery.device_from_description(location, mac) if device.model_name == 'Dimmer': add_devices([WemoDimmer(device)]) else: setup_bridge(device, add_devices)
def setup_platform(hass, config, add_devices, discovery_info=None): """Set up discovered WeMo switches.""" from pywemo import discovery if discovery_info is not None: location = discovery_info['ssdp_description'] mac = discovery_info['mac_address'] device = discovery.device_from_description(location, mac) if device.model_name == 'Dimmer': add_devices([WemoDimmer(device)]) else: setup_bridge(device, add_devices)
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up discovered WeMo humidifiers.""" from pywemo import discovery if DATA_KEY not in hass.data: hass.data[DATA_KEY] = {} if discovery_info is None: return location = discovery_info['ssdp_description'] mac = discovery_info['mac_address'] try: device = WemoHumidifier( discovery.device_from_description(location, mac)) except (requests.exceptions.ConnectionError, requests.exceptions.Timeout) as err: _LOGGER.error('Unable to access %s (%s)', location, err) raise PlatformNotReady hass.data[DATA_KEY][device.entity_id] = device add_entities([device]) def service_handle(service): """Handle the WeMo humidifier services.""" entity_ids = service.data.get(ATTR_ENTITY_ID) humidifiers = [device for device in hass.data[DATA_KEY].values() if device.entity_id in entity_ids] if service.service == SERVICE_SET_HUMIDITY: target_humidity = service.data.get(ATTR_TARGET_HUMIDITY) for humidifier in humidifiers: humidifier.set_humidity(target_humidity) elif service.service == SERVICE_RESET_FILTER_LIFE: for humidifier in humidifiers: humidifier.reset_filter_life() # Register service(s) hass.services.register( DOMAIN, SERVICE_SET_HUMIDITY, service_handle, schema=SET_HUMIDITY_SCHEMA) hass.services.register( DOMAIN, SERVICE_RESET_FILTER_LIFE, service_handle, schema=RESET_FILTER_LIFE_SCHEMA)
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up discovered WeMo switches.""" from pywemo import discovery if discovery_info is not None: location = discovery_info['ssdp_description'] mac = discovery_info['mac_address'] try: device = discovery.device_from_description(location, mac) except (requests.exceptions.ConnectionError, requests.exceptions.Timeout) as err: _LOGGER.error("Unable to access %s (%s)", location, err) raise PlatformNotReady if device: add_entities([WemoSwitch(device)])
def setup_platform(hass, config, add_entities, discovery_info=None): """Register discovered WeMo binary sensors.""" from pywemo import discovery if discovery_info is not None: location = discovery_info['ssdp_description'] mac = discovery_info['mac_address'] try: device = discovery.device_from_description(location, mac) except (requests.exceptions.ConnectionError, requests.exceptions.Timeout) as err: _LOGGER.error('Unable to access %s (%s)', location, err) raise PlatformNotReady if device: add_entities([WemoBinarySensor(hass, device)])
def setup_platform(hass, config, add_entities_callback, discovery_info=None): """Register discovered WeMo binary sensors.""" from pywemo import discovery if discovery_info is not None: location = discovery_info['ssdp_description'] mac = discovery_info['mac_address'] try: device = discovery.device_from_description(location, mac) except (requests.exceptions.ConnectionError, requests.exceptions.Timeout) as err: _LOGGER.error('Unable to access %s (%s)', location, err) raise PlatformNotReady if device: add_entities_callback([WemoBinarySensor(hass, device)])
def setup_platform(hass, config, add_entities, discovery_info=None): """Register discovered WeMo binary sensors.""" if discovery_info is not None: location = discovery_info["ssdp_description"] mac = discovery_info["mac_address"] try: device = discovery.device_from_description(location, mac) except ( requests.exceptions.ConnectionError, requests.exceptions.Timeout, ) as err: _LOGGER.error("Unable to access %s (%s)", location, err) raise PlatformNotReady if device: add_entities([WemoBinarySensor(hass, device)])
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up discovered WeMo switches.""" from pywemo import discovery if discovery_info is not None: location = discovery_info['ssdp_description'] mac = discovery_info['mac_address'] try: device = discovery.device_from_description(location, mac) except (requests.exceptions.ConnectionError, requests.exceptions.Timeout) as err: _LOGGER.error('Unable to access %s (%s)', location, err) raise PlatformNotReady if device.model_name == 'Dimmer': add_entities([WemoDimmer(device)]) else: setup_bridge(device, add_entities)
def setup_platform(hass, config, add_devices_callback, discovery_info=None): """ Find and return WeMo switches. """ import pywemo import pywemo.discovery as discovery if discovery_info is not None: device = discovery.device_from_description(discovery_info[2]) if device: add_devices_callback([WemoSwitch(device)]) return logging.getLogger(__name__).info("Scanning for WeMo devices") switches = pywemo.discover_devices() # Filter out the switches and wrap in WemoSwitch object add_devices_callback( [WemoSwitch(switch) for switch in switches if isinstance(switch, pywemo.Switch)])
def setup_platform(hass, config, add_devices_callback, discovery_info=None): """ Find and return WeMo switches. """ import pywemo import pywemo.discovery as discovery if discovery_info is not None: device = discovery.device_from_description(discovery_info) if device: add_devices_callback([WemoSwitch(device)]) return logging.getLogger(__name__).info("Scanning for WeMo devices") switches = pywemo.discover_devices() # Filter out the switches and wrap in WemoSwitch object add_devices_callback( [WemoSwitch(switch) for switch in switches if isinstance(switch, pywemo.Switch)])
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up discovered WeMo switches.""" if discovery_info is not None: location = discovery_info["ssdp_description"] mac = discovery_info["mac_address"] try: device = discovery.device_from_description(location, mac) except ( requests.exceptions.ConnectionError, requests.exceptions.Timeout, ) as err: _LOGGER.error("Unable to access %s (%s)", location, err) raise PlatformNotReady if device.model_name == "Dimmer": add_entities([WemoDimmer(device)]) else: setup_bridge(device, add_entities)
def setup_platform(hass, config, add_devices_callback, discovery_info=None): """ Find and return WeMo switches. """ import pywemo import pywemo.discovery as discovery if discovery_info is not None: location = discovery_info[2] mac = discovery_info[3] device = discovery.device_from_description(location, mac) if device: add_devices_callback([WemoSwitch(device)]) return _LOGGER.info("Scanning for WeMo devices.") switches = pywemo.discover_devices() # Filter out the switches and wrap in WemoSwitch object add_devices_callback( [WemoSwitch(switch) for switch in switches if isinstance(switch, pywemo.Switch)])
devices = discover_devices() print("%d found" % (len(devices))) else: print("Attempting direct connection...") port = probe_wemo(args.name) if port is not None: # This also matches https, but I'm pretty sure the current line # of WeMo devices don't have enough onboard memory for https if args.name.startswith("http"): urlwport = "%s:%s/setup.xml" % (args.name, port) else: urlwport = "http://%s:%s/setup.xml" % (args.name, port) # print(urlwport) d = device_from_description(urlwport) # Hack to use the existing logic devices = [d] else: print("No WeMo devices found :(") print("Are you on the same network *and* subnet?") if devices != []: reqPlugs = {} allPlugs = [] # We only need to do this if we didn't specify the direct connection if args.direct is False: print("Making sure plug with name %s was found..." % (args.name)) for each in devices: # Only look at switches; could check each.model_name (Socket)