def _main():
    api = ConnectAPI()
    devices = api.list_connected_devices().data
    if not devices:
        raise Exception("No connected devices registered. Aborting")

    # get list of presubscriptions
    presubscriptions = api.list_presubscriptions()
    print("List of presubscriptions: %r" % presubscriptions)
    device_id = devices[0].id
    # Get list of resources on a device
    resources = api.list_resources(device_id)
    # Get observable resource
    resource_uri = filter(lambda r: r.observable, resources)[0].path
    # Set new presubscription
    api.update_presubscriptions([{
        "device_id": device_id,
        "resource_paths": [resource_uri]
    }])
    # Subscription will be automatically set when a device with this id and resource path
    # will be connected

    # List presubscriptions
    presubscriptions = api.list_presubscriptions()
    print("List of presubscriptions after adding new presubscription: %r" %
          presubscriptions)
    # Delete presubscription
    api.delete_presubscriptions()
    presubscriptions = api.list_presubscriptions()
    print("List of presubscriptions after deleting all presubscriptions: %r" %
          presubscriptions)
def _main():
    api = ConnectAPI()
    api.start_notifications()
    devices = api.list_connected_devices().data
    if not devices:
        raise Exception("No connected devices registered. Aborting")
    device_id = "015e9a938ff100000000000100100019"
    api.delete_device_subscriptions(device_id)
    api.list_presubscriptions()

    api.add_resource_subscription_async(device_id, INCRIMENTAL_RESOURCE,
                                        _callback_fn)
    api.add_resource_subscription_async(device_id, VOLTAGE_RESOURCE,
                                        _callback_fn)
    api.add_resource_subscription_async(device_id, CURRENT_RESOURCE,
                                        _callback_fn)
    api.add_resource_subscription_async(device_id, POWER_RESOURCE,
                                        _callback_fn)
    while True:
        time.sleep(0.1)