How to use pywemo - 10 common examples

To help you get started, we’ve selected a few pywemo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pavoni / pywemo / pywemo / ouimeaux_device / api / xsd / service.py View on Github external
def gds_parse_datetime(self, input_data, node, input_name=''):
            tz = None
            if input_data[-1] == 'Z':
                tz = GeneratedsSuper._FixedOffsetTZ(0, 'GMT')
                input_data = input_data[:-1]
            else:
                results = GeneratedsSuper.tzoff_pattern.search(input_data)
                if results is not None:
                    tzoff_parts = results.group(2).split(':')
                    tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1])
                    if results.group(1) == '-':
                        tzoff *= -1
                    tz = GeneratedsSuper._FixedOffsetTZ(
                        tzoff, results.group(0))
                    input_data = input_data[:-6]
            if len(input_data.split('.')) > 1:
                dt = datetime.strptime(
                        input_data, '%Y-%m-%dT%H:%M:%S.%f')
            else:
                dt = datetime.strptime(
                        input_data, '%Y-%m-%dT%H:%M:%S')
            return dt.replace(tzinfo = tz)
github pavoni / pywemo / pywemo / ouimeaux_device / api / xsd / service.py View on Github external
def gds_parse_date(self, input_data, node, input_name=''):
            tz = None
            if input_data[-1] == 'Z':
                tz = GeneratedsSuper._FixedOffsetTZ(0, 'GMT')
                input_data = input_data[:-1]
            else:
                results = GeneratedsSuper.tzoff_pattern.search(input_data)
                if results is not None:
                    tzoff_parts = results.group(2).split(':')
                    tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1])
                    if results.group(1) == '-':
                        tzoff *= -1
                    tz = GeneratedsSuper._FixedOffsetTZ(
                        tzoff, results.group(0))
                    input_data = input_data[:-6]
            return datetime.strptime(input_data,
                '%Y-%m-%d').replace(tzinfo = tz)
        def gds_str_lower(self, instring):
github pavoni / pywemo / pywemo / ouimeaux_device / api / xsd / device.py View on Github external
def gds_parse_date(self, input_data, node, input_name=''):
            tz = None
            if input_data[-1] == 'Z':
                tz = GeneratedsSuper._FixedOffsetTZ(0, 'GMT')
                input_data = input_data[:-1]
            else:
                results = GeneratedsSuper.tzoff_pattern.search(input_data)
                if results is not None:
                    tzoff_parts = results.group(2).split(':')
                    tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1])
                    if results.group(1) == '-':
                        tzoff *= -1
                    tz = GeneratedsSuper._FixedOffsetTZ(
                        tzoff, results.group(0))
                    input_data = input_data[:-6]
            return datetime.strptime(input_data,
                '%Y-%m-%d').replace(tzinfo = tz)
        def gds_str_lower(self, instring):
github pavoni / pywemo / pywemo / ouimeaux_device / api / xsd / device.py View on Github external
def gds_parse_date(self, input_data, node, input_name=''):
            tz = None
            if input_data[-1] == 'Z':
                tz = GeneratedsSuper._FixedOffsetTZ(0, 'GMT')
                input_data = input_data[:-1]
            else:
                results = GeneratedsSuper.tzoff_pattern.search(input_data)
                if results is not None:
                    tzoff_parts = results.group(2).split(':')
                    tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1])
                    if results.group(1) == '-':
                        tzoff *= -1
                    tz = GeneratedsSuper._FixedOffsetTZ(
                        tzoff, results.group(0))
                    input_data = input_data[:-6]
            return datetime.strptime(input_data,
                '%Y-%m-%d').replace(tzinfo = tz)
        def gds_str_lower(self, instring):
github pavoni / pywemo / pywemo / ouimeaux_device / __init__.py View on Github external
def __init__(self, url, mac, rediscovery_enabled=True):
        """Create a WeMo device."""
        self._state = None
        self.basic_state_params = {}
        base_url = url.rsplit('/', 1)[0]
        parsed_url = urlparse(url)
        self.host = parsed_url.hostname
        self.port = parsed_url.port
        self.retrying = False
        self.mac = mac
        self.rediscovery_enabled = rediscovery_enabled
        xml = requests.get(url, timeout=10)
        self._config = deviceParser.parseString(xml.content).device
        service_list = self._config.serviceList
        self.services = {}
        for svc in service_list.service:
            svcname = svc.get_serviceType().split(':')[-2]
            service = Service(self, svc, base_url)
            service.eventSubURL = base_url + svc.get_eventSubURL()
            self.services[svcname] = service
            setattr(self, svcname, service)
github home-assistant / home-assistant / homeassistant / components / wemo / binary_sensor.py View on Github external
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)])
github home-assistant / home-assistant / homeassistant / components / wemo / switch.py View on Github external
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:
            add_entities([WemoSwitch(device)])
github home-assistant / home-assistant / homeassistant / components / wemo / light.py View on Github external
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)
github home-assistant / home-assistant / homeassistant / components / wemo.py View on Github external
def discover_wemo_devices(now):
        """Run discovery for WeMo devices."""
        _LOGGER.debug("Beginning WeMo device discovery...")
        _LOGGER.debug("Adding statically configured WeMo devices...")
        for host, port in config.get(DOMAIN, {}).get(CONF_STATIC, []):
            url = setup_url_for_address(host, port)

            if not url:
                _LOGGER.error(
                    'Unable to get description url for WeMo at: %s',
                    '{}:{}'.format(host, port) if port else host)
                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))
github theyosh / TerrariumPI / terrariumSwitch.py View on Github external
def set_hardware_state(self, state, force = False):
    port = pywemo.ouimeaux_device.probe_wemo(self.get_address())
    device = pywemo.discovery.device_from_description(terrariumPowerSwitchWeMo.URL.format(self.get_address(), port), None)
    if state is terrariumPowerSwitch.ON:
      device.on()
    else:
      device.off()