Beispiel #1
0
def get_devices_from_response_dict(response_dict, filter_key):
    """
    :rtype: list of WinkDevice
    """
    items = response_dict.get('data')

    devices = []

    keys = DEVICE_ID_KEYS.values()
    if filter_key:
        keys = [filter_key]

    api_interface = WinkApiInterface()

    for item in items:
        for key in keys:
            if not __device_is_visible(item, key):
                continue

            if key == "powerstrip_id":
                devices.extend(__get_outlets_from_powerstrip(item, api_interface))
                continue  # Don't capture the powerstrip itself as a device, only the individual outlets

            if key == "sensor_pod_id":
                subsensors = _get_subsensors_from_sensor_pod(item, api_interface)
                if subsensors:
                    devices.extend(subsensors)

            devices.append(build_device(item, api_interface))

    return devices
Beispiel #2
0
def get_devices_from_response_dict(response_dict, filter_key):
    """
    :rtype: list of WinkDevice
    """
    items = response_dict.get('data')

    devices = []

    keys = DEVICE_ID_KEYS.values()
    if filter_key:
        keys = [filter_key]

    api_interface = WinkApiInterface()

    for item in items:
        for key in keys:
            if not __device_is_visible(item, key):
                continue

            if key == "powerstrip_id":
                devices.extend(
                    __get_outlets_from_powerstrip(item, api_interface))
                continue  # Don't capture the powerstrip itself as a device, only the individual outlets

            if key == "sensor_pod_id":
                subsensors = _get_subsensors_from_sensor_pod(
                    item, api_interface)
                if subsensors:
                    devices.extend(subsensors)

            devices.append(build_device(item, api_interface))

    return devices
Beispiel #3
0
def get_devices(device_type):
    arequest_url = "{}/users/me/wink_devices".format(WinkApiInterface.BASE_URL)
    response = requests.get(arequest_url, headers=API_HEADERS)
    if response.status_code == 200:
        response_dict = response.json()
        filter_key = DEVICE_ID_KEYS.get(device_type)
        return get_devices_from_response_dict(response_dict, filter_key)

    if response.status_code == 401:
        raise WinkAPIException("401 Response from Wink API.  Maybe Bearer token is expired?")
    else:
        raise WinkAPIException("Unexpected")
Beispiel #4
0
def get_devices(device_type):
    arequest_url = "{}/users/me/wink_devices".format(WinkApiInterface.BASE_URL)
    response = requests.get(arequest_url, headers=API_HEADERS)
    if response.status_code == 200:
        response_dict = response.json()
        filter_key = DEVICE_ID_KEYS.get(device_type)
        return get_devices_from_response_dict(response_dict, filter_key)

    if response.status_code == 401:
        raise WinkAPIException(
            "401 Response from Wink API.  Maybe Bearer token is expired?")
    else:
        raise WinkAPIException("Unexpected")
Beispiel #5
0
def __get_sensor_from_hub(item, api_interface, filter_key):
    if filter_key != 'hub_id':
        return []
    keys = list(DEVICE_ID_KEYS.values())
    # Most devices have a hub_id, but we only want the actual hub.
    # This will only return hubs by checking for any other keys
    # being present along with the hub_id
    skip = False
    for key in keys:
        if key == "hub_id":
            continue
        if item.get(key, None) is not None:
            skip = True
    if skip:
        return []
    else:
        return [WinkHub(item, api_interface)]
Beispiel #6
0
def __get_sensor_from_hub(item, api_interface, filter_key):
    if filter_key != 'hub_id':
        return []
    keys = list(DEVICE_ID_KEYS.values())
    # Most devices have a hub_id, but we only want the actual hub.
    # This will only return hubs by checking for any other keys
    # being present along with the hub_id
    skip = False
    for key in keys:
        if key == "hub_id":
            continue
        if item.get(key, None) is not None:
            skip = True
    if skip:
        return []
    else:
        return [WinkHub(item, api_interface)]
Beispiel #7
0
def get_devices(device_type):
    response_dict = wink_api_fetch()
    filter_key = DEVICE_ID_KEYS.get(device_type)
    return get_devices_from_response_dict(response_dict, filter_key)
Beispiel #8
0
def get_devices(device_type):
    response_dict = wink_api_fetch()
    filter_key = DEVICE_ID_KEYS.get(device_type)
    return get_devices_from_response_dict(response_dict, filter_key)