{ "info": { "author": "DataArt (http://dataart.com)", "author_email": "info@devicehive.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Console", "Intended Audience :: Developers", "Intended Audience :: Information Technology", "License :: OSI Approved :: Apache Software License", "Operating System :: MacOS", "Operating System :: Microsoft :: Windows", "Operating System :: POSIX", "Operating System :: Unix", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Home Automation", "Topic :: Internet", "Topic :: Software Development :: Embedded Systems" ], "description": "|License| |PyPI| |Build Status|\n\nDevicehive\n==========\n\nThe simplest way to create a client is to use ``DeviceHiveApi`` class.\nIf you need to handle server events such as ``handle_command_insert``,\n``handle_command_update`` or ``handle_notification`` you'll have to\nextend ``Handler`` class and use ``DeviceHive`` class for it.\n\nCreating a client using DeviceHiveApi class\n-------------------------------------------\n\nFirst of all you need to create ``DeviceHiveApi`` object. Then you can\nuse this object for for API calls.\n\nExample:\n\n.. code:: python\n\n from devicehive import DeviceHiveApi\n\n\n url = 'http://playground.devicehive.com/api/rest'\n refresh_token = 'SOME_REFRESH_TOKEN'\n device_hive_api = DeviceHiveApi(url, refresh_token=refresh_token)\n\nWebsocket protocol\n~~~~~~~~~~~~~~~~~~\n\nIf you want to use ``Websocket`` protocol you need only to specify the\nurl:\n\n.. code:: python\n\n url = 'ws://playground.devicehive.com/api/websocket'\n\nAuthentication\n~~~~~~~~~~~~~~\n\nThere are three ways of initial authentication:\n\n- Using refresh token\n- Using access token\n- Using login and password\n\nExamples:\n\n.. code:: python\n\n from devicehive import DeviceHiveApi\n\n\n url = 'ws://playground.devicehive.com/api/websocket'\n device_hive_api = DeviceHiveApi(url, refresh_token='SOME_REFRESH_TOKEN')\n\n.. code:: python\n\n from devicehive import DeviceHiveApi\n\n\n url = 'ws://playground.devicehive.com/api/websocket'\n device_hive_api = DeviceHiveApi(url, access_token='SOME_ACCESS_TOKEN')\n\n.. code:: python\n\n from devicehive import DeviceHiveApi\n\n\n url = 'ws://playground.devicehive.com/api/websocket'\n device_hive_api = DeviceHiveApi(url, login='SOME_LOGIN', password='SOME_PASSWORD')\n\nInfo\n~~~~\n\n``get_info()`` method returns ``dict`` with the next fields:\n\n- ``api_version``\n- ``server_timestamp``\n- ``rest_server_url``\n- ``websocket_server_url``\n\n``get_cluster_info()`` method returns ``dict`` with the next fields:\n\n- ``bootstrap.servers``\n- ``zookeeper.connect``\n\nExample:\n\n.. code:: python\n\n from devicehive import DeviceHiveApi\n\n\n url = 'http://playground.devicehive.com/api/rest'\n refresh_token = 'SOME_REFRESH_TOKEN'\n device_hive_api = DeviceHiveApi(url, refresh_token=refresh_token)\n info = device_hive_api.get_info()\n print(info)\n cluster_info = device_hive_api.get_cluster_info()\n print(cluster_info)\n\nProperties\n~~~~~~~~~~\n\n``get_property(name)`` method returns ``dict`` with the next fields:\n\n- ``entity_version``\n- ``name``\n- ``value``\n\n``set_property(name, value)`` method returns entity version.\n\n``delete_property(name)`` method does not return anything.\n\nExample:\n\n.. code:: python\n\n from devicehive import DeviceHiveApi\n\n\n url = 'http://playground.devicehive.com/api/rest'\n refresh_token = 'SOME_REFRESH_TOKEN'\n device_hive_api = DeviceHiveApi(url, refresh_token=refresh_token)\n name = 'user.login.lastTimeoutSent'\n entity_version = device_hive_api.set_property(name, 'value')\n print(entity_version)\n prop = device_hive_api.get_property(name)\n print(prop)\n device_hive_api.delete_property(name)\n\nTokens\n~~~~~~\n\n``create_token(user_id, expiration, actions, network_ids, device_ids)``\nmethod returns ``dict`` with the next fields:\n\n- ``access_token``\n- ``refresh_token``\n\nonly ``user_id`` is required.\n\n``refresh_token()`` method refreshes the access token and returns it.\n\nExample:\n\n.. code:: python\n\n from devicehive import DeviceHiveApi\n\n\n url = 'http://playground.devicehive.com/api/rest'\n refresh_token = 'SOME_REFRESH_TOKEN'\n device_hive_api = DeviceHiveApi(url, refresh_token=refresh_token)\n tokens = device_hive_api.create_token(1)\n print(tokens)\n access_token = device_hive_api.refresh_token()\n print(access_token)\n\nDevices\n~~~~~~~\n\n``list_devices(name, name_pattern, network_id, network_name, sort_field, sort_order, take, skip)``\nmethod returns list of ``Device`` objects. All args are optional.\n\n``get_device(device_id)`` method returns ``Device`` object.\n\n``put_device(device_id, name, data, network_id, is_blocked)`` method\nreturns ``Device`` object. Only ``device_id`` is required.\n\n``list_commands(device_id, start, end, command, status, sort_field, sort_order, take, skip)``\nmethod returns list of ``Command`` objects. Only ``device_id`` is\nrequired.\n\n``send_command(device_id, command_name, parameters, lifetime, timestamp, status, result)``\nmethod returns ``Command`` object. Only ``device_id`` and\n``command_name`` are required.\n\n``list_notifications(device_id, start, end, notification, sort_field, sort_order, take, skip)``\nmethod returns list of ``Notification`` object. Only ``device_id`` is\nrequired.\n\n``send_notification(device_id, notification_name, parameters, timestamp)``\nmethod returns ``Notification`` object. Only ``device_id`` and\n``notification_name`` are required.\n\nDevice object\n^^^^^^^^^^^^^\n\nProperties:\n\n- ``id`` (read only)\n- ``name``\n- ``data``\n- ``network_id``\n- ``device_type_id``\n- ``is_blocked``\n\nMethods:\n\n- ``save()`` method does not return anything.\n- ``remove()`` method does not return anything.\n- ``list_commands(start, end, command, status, sort_field, sort_order, take, skip)``\n method returns list of ``Command`` objects. All args are optional.\n- ``send_command(command_name, parameters, lifetime, timestamp, status, result)``\n method returns ``Command`` object. Only ``command_name`` is required.\n- ``list_notifications(start, end, notification, sort_field, sort_order, take, skip)``\n method returns list of ``Notification`` objects. All args are\n optional.\n- ``send_notification(notification_name, parameters, timestamp)``\n method returns ``Notification`` object. Only ``notification_name`` is\n required.\n\nCommand object\n^^^^^^^^^^^^^^\n\nProperties:\n\n- ``id`` (read only)\n- ``user_id`` (read only)\n- ``command`` (read only)\n- ``parameters`` (read only)\n- ``lifetime`` (read only)\n- ``timestamp`` (read only)\n- ``last_updated`` (read only)\n- ``status``\n- ``result``\n\nMethods:\n\n- ``save()`` method does not return anything.\n\nNotification object\n^^^^^^^^^^^^^^^^^^^\n\nProperties:\n\n- ``device_id`` (read only)\n- ``id`` (read only)\n- ``notification`` (read only)\n- ``parameters`` (read only)\n- ``timestamp`` (read only)\n\nExample:\n\n.. code:: python\n\n from devicehive import DeviceHiveApi\n\n\n url = 'http://playground.devicehive.com/api/rest'\n refresh_token = 'SOME_REFRESH_TOKEN'\n device_hive_api = DeviceHiveApi(url, refresh_token=refresh_token)\n device_id = 'example-device'\n device = device_hive_api.put_device(device_id)\n device.name = 'new-device-name'\n device.data = {'key': 'value'}\n device.save()\n devices = device_hive_api.list_devices()\n for device in devices:\n print('Device: %s, name: %s, data: %s' % (device.id, device.name,\n device.data))\n device.remove()\n\nNetworks\n~~~~~~~~\n\n``list_networks(name, name_pattern, sort_field, sort_order, take, skip)``\nmethod returns list of ``Network`` objects. All args are optional.\n\n``get_network(network_id)`` method returns ``Network`` object.\n\n``create_network(name, description)`` method returns ``Network`` object.\n\nNetwork object\n^^^^^^^^^^^^^^\n\nProperties:\n\n- ``id`` (read only)\n- ``name``\n- ``description``\n\nMethods:\n\n- ``save()`` method does not return anything.\n- ``remove(force)`` method does not return anything. All args are\n optional.\n\nExample:\n\n.. code:: python\n\n from devicehive import DeviceHiveApi\n\n\n url = 'http://playground.devicehive.com/api/rest'\n refresh_token = 'SOME_REFRESH_TOKEN'\n device_hive_api = DeviceHiveApi(url, refresh_token=refresh_token)\n network_name = 'example-name'\n network_description = 'example-description'\n network = device_hive_api.create_network(network_name, network_description)\n print(network.name)\n\nDevice types\n~~~~~~~~~~~~\n\n``list_device_types(name, name_pattern, sort_field, sort_order, take, skip)``\nmethod returns list of ``DeviceType`` objects. All args are optional.\n\n``get_device_type(device_type_id)`` method returns ``DeviceType``\nobject.\n\n``create_device_type(name, description)`` method returns ``DeviceType``\nobject.\n\nDeviceType object\n^^^^^^^^^^^^^^^^^\n\nProperties:\n\n- ``id`` (read only)\n- ``name``\n- ``description``\n\nMethods:\n\n- ``save()`` method does not return anything.\n- ``remove(force)`` method does not return anything. All args are\n optional.\n\nExample:\n\n.. code:: python\n\n from devicehive import DeviceHiveApi\n\n\n url = 'http://playground.devicehive.com/api/rest'\n refresh_token = 'SOME_REFRESH_TOKEN'\n device_hive_api = DeviceHiveApi(url, refresh_token=refresh_token)\n device_type_name = 'example-name'\n device_type_description = 'example-description'\n device_type = device_hive_api.create_device_type(device_type_name,\n device_type_description)\n print(device_type.name)\n\nUsers\n~~~~~\n\n``list_users(login, login_pattern, role, status, sort_field, sort_order, take, skip)``\nmethod returns list of ``User`` objects. All args are optional.\n\n``get_current_user()`` method returns ``User`` object.\n\n``get_user(user_id)`` method returns ``User`` object.\n\n``create_user(self, login, password, role, data, all_device_types_available)``\nmethod returns ``User`` object.\n\nUser object\n^^^^^^^^^^^\n\nProperties:\n\n- ``id`` (read only)\n- ``login`` (read only)\n- ``last_login`` (read only)\n- ``intro_reviewed`` (read only)\n- ``all_device_types_available`` (read only)\n- ``role``\n- ``status``\n- ``data``\n\nMethods:\n\n- ``save()`` method does not return anything.\n- ``update_password(password)`` method does not return anything.\n- ``remove()`` method does not return anything.\n- ``list_networks()`` method Returns list of ``Network`` objects.\n- ``list_device_types()`` method Returns list of ``DeviceType``\n objects.\n- ``assign_network(network_id)`` method does not return anything.\n- ``unassign_network(network_id)`` method does not return anything.\n- ``assign_device_type(device_type_id)`` method does not return\n anything.\n- ``unassign_device_type(device_type_id)`` method does not return\n anything.\n- ``allow_all_device_types()`` method does not return anything.\n- ``disallow_all_device_types()`` method does not return anything.\n\nExample:\n\n.. code:: python\n\n from devicehive import DeviceHiveApi\n from devicehive.user import User\n\n\n url = 'http://playground.devicehive.com/api/rest'\n refresh_token = 'SOME_REFRESH_TOKEN'\n device_hive_api = DeviceHiveApi(url, refresh_token=refresh_token)\n login = 'example-login'\n password = 'example-password'\n role = User.CLIENT_ROLE\n data = {'key': 'value'}\n user = device_hive_api.create_user(login, password, role, data)\n print(user.login)\n\nCreating a client using DeviceHive class\n----------------------------------------\n\nFirst of all you need to create custom ``Handler`` class.\n\nExample of creating custom ``Handler`` class:\n\n.. code:: python\n\n from devicehive import Handler\n\n\n class SimpleHandler(Handler):\n\n def handle_connect(self):\n info = self.api.get_info()\n print(info)\n self.api.disconnect()\n\n``handle_connect`` is the only one required method. If you want to\nhandle server events you'll heed to implement ``handle_command_insert``,\n``handle_command_update`` and ``handle_notification`` methods.\n\nExample:\n\n.. code:: python\n\n from devicehive import Handler\n\n\n class SimpleHandler(Handler):\n \n def handle_connect(self):\n device_ids = ['example-device-1', 'example-device-2']\n for device_id in device_ids:\n device = self.api.put_device(device_id)\n device.subscribe_insert_commands()\n device.subscribe_update_commands()\n device.subscribe_notifications()\n\n def handle_command_insert(self, command):\n print(command.command)\n\n def handle_command_update(self, command):\n print(command.command)\n\n def handle_notification(self, notification):\n print(notification.notification)\n\nThe second step is to use ``DeviceHive`` class for creating connection\nto the server.\n\nExample:\n\n.. code:: python\n\n from devicehive import Handler\n from devicehive import DeviceHive\n\n\n class SimpleHandler(Handler):\n\n def handle_connect(self):\n device_ids = ['example-device-1', 'example-device-2']\n for device_id in device_ids:\n device = self.api.put_device(device_id)\n device.subscribe_insert_commands()\n device.subscribe_update_commands()\n device.subscribe_notifications()\n\n def handle_command_insert(self, command):\n print(command.command)\n\n def handle_command_update(self, command):\n print(command.command)\n\n def handle_notification(self, notification):\n print(notification.notification)\n\n\n url = 'http://playground.devicehive.com/api/rest'\n refresh_token = 'SOME_REFRESH_TOKEN'\n dh = DeviceHive(SimpleHandler)\n dh.connect(url, refresh_token=refresh_token)\n\nCustom handler args\n~~~~~~~~~~~~~~~~~~~\n\nIf you need to initialize your handler you can do it the next way:\n\n.. code:: python\n\n from devicehive import Handler\n from devicehive import DeviceHive\n\n\n class SimpleHandler(Handler):\n\n def __init__(self, api, some_arg, some_kwarg):\n Handler.__init__(self, api)\n self._some_arg = some_arg\n self._some_kwarg = some_kwarg\n\n def handle_connect(self):\n info = self.api.get_info()\n print(info)\n self.api.disconnect()\n\n device_hive = DeviceHive(SimpleHandler, 'some_arg', some_kwarg='some_kwarg')\n\nWebsocket protocol\n~~~~~~~~~~~~~~~~~~\n\nIf you want to use ``Websocket`` protocol you need only to specify the\nurl:\n\n.. code:: python\n\n url = 'ws://playground.devicehive.com/api/websocket'\n\nAuthentication\n~~~~~~~~~~~~~~\n\nThere are three ways of initial authentication:\n\n- Using refresh token\n- Using access token\n- Using login and password\n\nExamples:\n\n.. code:: python\n\n url = 'ws://playground.devicehive.com/api/websocket'\n device_hive.connect(url, refresh_token='SOME_REFRESH_TOKEN')\n\n.. code:: python\n\n url = 'ws://playground.devicehive.com/api/websocket'\n device_hive.connect(url, access_token='SOME_ACCESS_TOKEN')\n\n.. code:: python\n\n url = 'ws://playground.devicehive.com/api/websocket'\n device_hive.connect(url, login='SOME_LOGIN', password='SOME_PASSWORD')\n\nAPI\n---\n\nAll api calls may be done via ``api`` object. This object available\ninside custom handler with ``self.api`` property.\n\nAPI info\n~~~~~~~~\n\n``self.api.get_info()`` method returns ``dict``. ``get_info`` method of\n``DeviceHiveApi`` class is the wrapper on top of this call.\n\n``self.api.get_cluster_info()`` method returns ``dict``.\n``get_cluster_info`` method of ``DeviceHiveApi`` class is the wrapper on\ntop of this call.\n\nSee the description of ``DeviceHiveApi`` `info <#info>`__ methods for\nmore details.\n\nExample:\n\n.. code:: python\n\n from devicehive import Handler\n\n\n class SimpleHandler(Handler):\n\n def handle_connect(self):\n info = self.api.get_info()\n print(info)\n cluster_info = self.api.get_cluster_info()\n print(cluster_info)\n self.api.disconnect()\n\nAPI properties\n~~~~~~~~~~~~~~\n\n``self.api.get_property(name)`` method returns ``dict``.\n``get_property`` method of ``DeviceHiveApi`` class is the wrapper on top\nof this call.\n\n``self.api.set_property(name, value)`` method returns entity version.\n``set_property`` method of ``DeviceHiveApi`` class is the wrapper on top\nof this call.\n\n``self.api.delete_property(name)`` method does not return anything.\n``delete_property`` method of ``DeviceHiveApi`` class is the wrapper on\ntop of this call.\n\nSee the description of ``DeviceHiveApi`` `property <#properties>`__\nmethods for more details.\n\nExample:\n\n.. code:: python\n\n from devicehive import Handler\n\n\n class SimpleHandler(Handler):\n\n def handle_connect(self):\n name = 'user.login.lastTimeoutSent'\n prop = self.api.get_property(name)\n print(prop)\n entity_version = self.api.get_property(name, 'value')\n print(entity_version)\n self.api.delete_property(name)\n self.api.disconnect()\n\nAPI tokens\n~~~~~~~~~~\n\n``self.api.create_token(user_id, expiration, actions, network_ids, device_ids)``\nmethod returns ``dict``. ``create_token`` method of ``DeviceHiveApi``\nclass is the wrapper on top of this call.\n\n``self.api.refresh_token()`` method refreshes the access token and\nreturns it. ``refresh_token`` method of ``DeviceHiveApi`` class is the\nwrapper on top of this call.\n\nSee the description of ``DeviceHiveApi`` `token <#tokens>`__ methods for\nmore details.\n\nExample:\n\n.. code:: python\n\n from devicehive import Handler\n\n\n class SimpleHandler(Handler):\n\n def handle_connect(self):\n tokens = self.api.create_token(1)\n print(tokens)\n access_token = self.api.refresh_token()\n print(access_token)\n self.api.disconnect()\n\nAPI commands subscription\n~~~~~~~~~~~~~~~~~~~~~~~~~\n\n``self.api.subscribe_insert_commands(device_id, network_ids, device_type_ids, names, timestamp)``\nmethod returns ``CommandsSubscription`` object.\n\n``self.api.subscribe_update_commands(device_id, network_ids, device_type_ids, names, timestamp)``\nmethod returns ``CommandsSubscription`` object.\n\nAPI CommandsSubscription object\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nProperties:\n\n- ``id`` (read only)\n\nMethods:\n\n- ``remove()`` method does not return anything.\n\nExample:\n\n.. code:: python\n\n from devicehive import Handler\n\n\n class SimpleHandler(Handler):\n insert_subscription = None\n update_subscription = None\n\n def handle_connect(self):\n device_id = 'example-device'\n device = self.api.put_device(device_id)\n command_name = 'example-command'\n self.insert_subscription = self.api.subscribe_insert_commands(\n device_id, [command_name])\n self.update_subscription= self.api.subscribe_update_commands(\n device_id, [command_name])\n command = device.send_command(command_name)\n command.status = 'new-status'\n command.save()\n\n def handle_command_insert(self, command):\n print('Command insert: %s, status: %s.' % (command.command,\n command.status))\n\n def handle_command_update(self, command):\n print('Command update: %s, status: %s.' % (command.command,\n command.status))\n self.insert_subscription.remove()\n self.update_subscription.remove()\n\nAPI notifications subscription\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n``self.api.subscribe_notifications(device_id, network_ids, device_type_ids, names, timestamp)``\nmethod returns ``NotificationsSubscription`` object.\n\nAPI NotificationsSubscription object\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nProperties:\n\n- ``id`` (read only)\n\nMethods:\n\n- ``remove()`` method does not return anything.\n\nExample:\n\n.. code:: python\n\n from devicehive import Handler\n\n\n class SimpleHandler(Handler):\n notification_subscription = None\n\n def handle_connect(self):\n device_id = 'example-device'\n device = self.api.put_device(device_id)\n notification_name = 'example-notification'\n self.notification_subscription = self.api.subscribe_notifications(\n device_id, [notification_name])\n device.send_notification(notification_name)\n\n def handle_notification(self, notification):\n print('Notification: %s.' % notification.notification)\n self.notification_subscription.remove()\n\nAPI devices\n~~~~~~~~~~~\n\n``self.api.list_devices(name, name_pattern, network_id, network_name, sort_field, sort_order, take, skip)``\nmethod returns list of ``Device`` objects. ``list_devices`` method of\n``DeviceHiveApi`` class is the wrapper on top of this call.\n\n``self.api.get_device(device_id)`` method returns ``Device`` object.\n``get_device`` method of ``DeviceHiveApi`` class is the wrapper on top\nof this call.\n\n``self.api.put_device(device_id, name, data, network_id, device_type_id, is_blocked)``\nmethod does not return anything. ``put_device`` method of\n``DeviceHiveApi`` class is the wrapper on top of this call.\n\n``self.api.list_commands(device_id, start, end, command, status, sort_field, sort_order, take, skip)``\nmethod returns list of ``Command`` objects. ``list_commands`` method of\n``DeviceHiveApi`` class is the wrapper on top of this call.\n\n``self.api.send_command(device_id, command_name, parameters, lifetime, timestamp, status, result)``\nmethod returns ``Command`` object. ``send_command`` method of\n``DeviceHiveApi`` class is the wrapper on top of this call.\n\n``self.api.list_notifications(device_id, start, end, notification, sort_field, sort_order, take, skip)``\nmethod returns list of ``Notification`` objects. ``list_notifications``\nmethod of ``DeviceHiveApi`` class is the wrapper on top of this call.\n\n``self.api.send_notification(device_id, notification_name, parameters, timestamp)``\nmethod returns ``Notification`` object. ``send_notification`` method of\n``DeviceHiveApi`` class is the wrapper on top of this call.\n\nSee the description of ``DeviceHiveApi`` `device <#devices>`__ methods\nfor more details.\n\nAPI device object\n^^^^^^^^^^^^^^^^^\n\nAPI device object has the same properties as `device\nobject <#device-object>`__.\n\nAPI device object has all methods from `device\nobject <#device-object>`__ and extends these methods with:\n\n- ``subscribe_insert_commands(names, timestamp)`` method returns\n ``CommandsSubscription`` object. All args are optional.\n- ``subscribe_update_commands(names, timestamp)`` method returns\n ``CommandsSubscription`` object. All args are optional.\n- ``subscribe_notifications(names, timestamp)`` method returns\n ``NotificationsSubscription`` object. All args are optional.\n\nAPI command object\n^^^^^^^^^^^^^^^^^^\n\nAPI command object has the same properties as `command\nobject <#command-object>`__.\n\nAPI command object has the same methods as `command\nobject <#command-object>`__.\n\nAPI notification object\n^^^^^^^^^^^^^^^^^^^^^^^\n\nAPI notification object has the same properties as `notification\nobject <#notification-object>`__\n\nExample:\n\n.. code:: python\n\n from devicehive import Handler\n\n\n class SimpleHandler(Handler):\n\n def handle_connect(self):\n device_id = 'example-device'\n device = self.api.put_device(device_id)\n device.name = 'new-device-name'\n device.data = {'key': 'value'}\n device.save()\n devices = self.api.list_devices()\n for device in devices:\n print('Device: %s, name: %s, data: %s' % (device.id, device.name,\n device.data))\n device.remove()\n self.api.disconnect()\n\nAPI networks\n~~~~~~~~~~~~\n\n``self.api.list_networks(name, name_pattern, sort_field, sort_order, take, skip)``\nmethod returns list of ``Network`` objects. ``list_networks`` method of\n``DeviceHiveApi`` class is the wrapper on top of this call.\n\n``self.api.get_network(network_id)`` method returns ``Network`` object.\n``get_network`` method of ``DeviceHiveApi`` class is the wrapper on top\nof this call.\n\n``self.api.create_network(name, description)`` method returns\n``Network`` object. ``create_network`` method of ``DeviceHiveApi`` class\nis the wrapper on top of this call.\n\nSee the description of ``DeviceHiveApi`` `network <#networks>`__ methods\nfor more details.\n\nAPI network object\n^^^^^^^^^^^^^^^^^^\n\nAPI network object has the same properties as `network\nobject <#network-object>`__.\n\nAPI network object has all methods from `network\nobject <#network-object>`__ and extends these methods with:\n\n- ``list_devices(name, name_pattern, sort_field, sort_order, take, skip)``\n method returns list of ``Device`` objects. All args are optional.\n- ``subscribe_insert_commands(names, timestamp)`` method returns\n ``CommandsSubscription`` object. All args are optional.\n- ``subscribe_update_commands(names, timestamp)`` method returns\n ``CommandsSubscription`` object. All args are optional.\n- ``subscribe_notifications(names, timestamp)`` method returns\n ``NotificationsSubscription`` object. All args are optional.\n\nExample:\n\n.. code:: python\n\n from devicehive import Handler\n\n\n class SimpleHandler(Handler):\n\n def handle_connect(self):\n network_name = 'example-name'\n network_description = 'example-description'\n network = self.api.create_network(network_name, network_description)\n print(network.name)\n self.api.disconnect()\n\nAPI device types\n~~~~~~~~~~~~~~~~\n\n``self.api.list_device_types(name, name_pattern, sort_field, sort_order, take, skip)``\nmethod returns list of ``DeviceType`` objects. ``list_device_types``\nmethod of ``DeviceHiveApi`` class is the wrapper on top of this call.\n\n``self.api.get_device_type(device_type_id)`` method returns\n``DeviceType`` object. ``get_device_type`` method of ``DeviceHiveApi``\nclass is the wrapper on top of this call.\n\n``self.api.create_device_type(name, description)`` method returns\n``DeviceType`` object. ``create_device_type`` method of\n``DeviceHiveApi`` class is the wrapper on top of this call.\n\nSee the description of ``DeviceHiveApi`` `device\ntypes <#device-types>`__ methods for more details.\n\nAPI device type object\n^^^^^^^^^^^^^^^^^^^^^^\n\nAPI device type object has the same properties as `device type\nobject <#devicetype-object>`__.\n\nAPI device type object has all methods from `device type\nobject <#devicetype-object>`__ and extends these methods with:\n\n- ``list_devices(name, name_pattern, sort_field, sort_order, take, skip)``\n method returns list of ``Device`` objects. All args are optional.\n- ``subscribe_insert_commands(names, timestamp)`` method returns\n ``CommandsSubscription`` object. All args are optional.\n- ``subscribe_update_commands(names, timestamp)`` method returns\n ``CommandsSubscription`` object. All args are optional.\n- ``subscribe_notifications(names, timestamp)`` method returns\n ``NotificationsSubscription`` object. All args are optional.\n\nExample:\n\n.. code:: python\n\n from devicehive import Handler\n\n\n class SimpleHandler(Handler):\n\n def handle_connect(self):\n device_type_name = 'example-name'\n device_type_description = 'example-description'\n device_type = self.api.create_device_type(device_type_name, device_type_description)\n print(device_type.name)\n self.api.disconnect()\n\nAPI users\n~~~~~~~~~\n\n``self.api.list_users(login, login_pattern, role, status, sort_field, sort_order, take, skip)``\nmethod returns list of ``User`` objects. ``list_users`` method of\n``DeviceHiveApi`` class is the wrapper on top of this call.\n\n``self.api.get_current_user()`` method returns ``User`` object.\n``get_current_user`` method of ``DeviceHiveApi`` class is the wrapper on\ntop of this call.\n\n``self.api.get_user(user_id)`` method returns ``User`` object.\n``get_user`` method of ``DeviceHiveApi`` class is the wrapper on top of\nthis call.\n\n``self.api.create_user(self, login, password, role, data, all_device_types_available)``\nmethod returns ``User`` object. ``create_user`` method of\n``DeviceHiveApi`` class is the wrapper on top of this call.\n\nSee the description of ``DeviceHiveApi`` `user <#users>`__ methods for\nmore details.\n\nAPI user object\n^^^^^^^^^^^^^^^\n\nAPI user object has the same properties as `user\nobject <#user-object>`__.\n\nAPI user object has the same methods as `user object <#user-object>`__.\n\nExample:\n\n.. code:: python\n\n from devicehive import Handler\n from devicehive.user import User\n\n\n class SimpleHandler(Handler):\n\n def handle_connect(self):\n login = 'example-login'\n password = 'example-password'\n role = User.CLIENT_ROLE\n data = {'key': 'value'}\n user = self.api.create_user(login, password, role, data)\n print(user.login)\n self.api.disconnect()\n\nAPI extended example\n--------------------\n\nHere we will create one endpoint which sends notifications and other\nendpoint which receives these notifications.\n\nOn the first we will create ``receiver.py``:\n\n.. code:: python\n\n from devicehive import Handler\n from devicehive import DeviceHive\n\n\n class ReceiverHandler(Handler):\n\n def __init__(self, api, device_id='simple-example-device',\n accept_command_name='accept_notifications'):\n Handler.__init__(self, api)\n self._device_id = device_id\n self._accept_command_name = accept_command_name\n self._device = None\n\n def handle_connect(self):\n self._device = self.api.put_device(self._device_id)\n self._device.subscribe_insert_commands([self._accept_command_name])\n self._device.subscribe_notifications()\n\n def handle_command_insert(self, command):\n print('Accept command \"%s\"' % self._accept_command_name)\n command.status = 'accepted'\n command.save()\n\n def handle_notification(self, notification):\n print('Notification \"%s\" received' % notification.notification)\n\n\n url = 'ws://playground.devicehive.com/api/websocket'\n refresh_token = 'SOME_REFRESH_TOKEN'\n dh = DeviceHive(ReceiverHandler)\n dh.connect(url, refresh_token=refresh_token)\n\nOn the next step we will create ``sender.py``\n\n.. code:: python\n\n from devicehive import Handler\n from devicehive import DeviceHive\n\n\n class SenderHandler(Handler):\n\n def __init__(self, api, device_id='simple-example-device',\n accept_command_name='accept_notifications',\n num_notifications=10):\n Handler.__init__(self, api)\n self._device_id = device_id\n self._accept_command_name = accept_command_name\n self._num_notifications = num_notifications\n self._device = None\n\n def _send_notifications(self):\n for num_notification in range(self._num_notifications):\n notification = '%s-notification' % num_notification\n self._device.send_notification(notification)\n print('Sending notification \"%s\"' % notification)\n self.api.disconnect()\n\n def handle_connect(self):\n self._device = self.api.get_device(self._device_id)\n self._device.send_command(self._accept_command_name)\n print('Sending command \"%s\"' % self._accept_command_name)\n self._device.subscribe_update_commands([self._accept_command_name])\n\n def handle_command_update(self, command):\n if command.status == 'accepted':\n print('Command \"%s\" accepted' % self._accept_command_name)\n self._send_notifications()\n\n\n url = 'http://playground.devicehive.com/api/rest'\n refresh_token = 'SOME_REFRESH_TOKEN'\n dh = DeviceHive(SenderHandler)\n dh.connect(url, refresh_token=refresh_token)\n\nRun ``python receiver.py`` in the first terminal. And\n``python sender.py`` in the second. The order of run is important.\n``receiver.py`` must be started first.\n\nDocker tests\n------------\n\nBuild image\n~~~~~~~~~~~\n\n::\n\n docker build -f Dockerfile.tests -t devicehive-tests .\n\nRun tests\n~~~~~~~~~\n\nYou can run tests with refresh\\_token by setting ``ADMIN_REFRESH_TOKEN``\nand/or ``CLIENT_REFRESH_TOKEN`` variable:\n\n::\n\n docker run -it -e ADMIN_REFRESH_TOKEN='SOME_ADMIN_REFRESH_TOKEN' devicehive-tests\n\nOr with access\\_token by setting ``ADMIN_ACCESS_TOKEN`` and/or\n``CLIENT_ACCESS_TOKEN`` variable:\n\n::\n\n docker run -it -e ADMIN_ACCESS_TOKEN='SOME_ADMIN_ACCESS_TOKEN' devicehive-tests\n\nOr with user login and password by setting ``ADMIN_LOGIN`` and\n``ADMIN_PASSWORD`` for admin account and/or ``CLIENT_LOGIN`` and\n``CLIENT_PASSWORD`` for client account.\n\n::\n\n docker run -it -e ADMIN_LOGIN='SOME_ADMIN_LOGIN' -e ADMIN_PASSWORD='SOME_ADMIN_PASSWORD' devicehive-tests\n\nTo run tests with enabled requests logging you need to change\n``LOG_LEVEL`` variable:\n\n::\n\n docker run -it -e ADMIN_REFRESH_TOKEN='SOME_ADMIN_REFRESH_TOKEN' -e LOG_LEVEL='DEBUG' devicehive-tests\n\nTo run the specific test you need to set ``TEST`` variable:\n\n::\n\n docker run -it -e TEST=test_api.py::test_get_info -e ADMIN_REFRESH_TOKEN='SOME_ADMIN_REFRESH_TOKEN' devicehive-tests\n\n.. |License| image:: https://img.shields.io/badge/License-Apache%202.0-blue.svg\n :target: LICENSE\n.. |PyPI| image:: https://img.shields.io/pypi/v/devicehive.svg\n :target: https://pypi.python.org/pypi/devicehive\n.. |Build Status| image:: https://travis-ci.org/devicehive/devicehive-python.svg?branch=master\n :target: https://travis-ci.org/devicehive/devicehive-python\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://devicehive.com", "keywords": "iot cloud m2m gateway embedded devicehive", "license": "Apache License 2.0", "maintainer": "", "maintainer_email": "", "name": "devicehive", "package_url": "https://pypi.org/project/devicehive/", "platform": "", "project_url": "https://pypi.org/project/devicehive/", "project_urls": { "Homepage": "https://devicehive.com" }, "release_url": "https://pypi.org/project/devicehive/2.1.6/", "requires_dist": null, "requires_python": "", "summary": "DeviceHive Python connectivity library", "version": "2.1.6" }, "last_serial": 3980883, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "fd47cba0374ca1cb282a0bbe5ebd1cc5", "sha256": "902343bd8a48b162b419b21d9e7e35270a6fa471a5a98b0e694300e76f504068" }, "downloads": -1, "filename": "devicehive-0.0.1.tar.gz", "has_sig": false, "md5_digest": "fd47cba0374ca1cb282a0bbe5ebd1cc5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 24649, "upload_time": "2017-08-22T11:49:35", "url": "https://files.pythonhosted.org/packages/40/fc/adce1ac83671395eba3a35fbcc58d0e8116f0cbc66c78095a49b90ca4ff6/devicehive-0.0.1.tar.gz" } ], "2.0.0": [ { "comment_text": "", "digests": { "md5": "ce13628adbfd4312049a9e4a69dffe9b", "sha256": "aa6515da703338fc1e34d4d1b2e5e89f9b18bca5c5b58de6ac3c1534fe0af71c" }, "downloads": -1, "filename": "devicehive-2.0.0.tar.gz", "has_sig": false, "md5_digest": "ce13628adbfd4312049a9e4a69dffe9b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 24636, "upload_time": "2017-08-22T11:51:45", "url": "https://files.pythonhosted.org/packages/85/72/d42189201c68cfe706a8317d6b2d41fadaeb1135485357d7472aa2e233a2/devicehive-2.0.0.tar.gz" } ], "2.0.1": [ { "comment_text": "", "digests": { "md5": "3ff9a24698c454dcf47f42d43efda0de", "sha256": "151691aa49fc9867c88e1db6ba4d3178e87d8a316a98a5d953d94504f5c34b4e" }, "downloads": -1, "filename": "devicehive-2.0.1.tar.gz", "has_sig": false, "md5_digest": "3ff9a24698c454dcf47f42d43efda0de", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 24912, "upload_time": "2017-08-25T14:36:16", "url": "https://files.pythonhosted.org/packages/07/de/8f6611cf06e1c87993d14b6d78ecd3883fd696338c25056bade84a0b45ef/devicehive-2.0.1.tar.gz" } ], "2.0.2": [ { "comment_text": "", "digests": { "md5": "fca2df896d52cb9460b0383515743315", "sha256": "3b7db204c9ddf8547ece080259a235ead9c42676e277e77ed06b687178906dd7" }, "downloads": -1, "filename": "devicehive-2.0.2.tar.gz", "has_sig": false, "md5_digest": "fca2df896d52cb9460b0383515743315", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 25099, "upload_time": "2017-09-20T12:51:32", "url": "https://files.pythonhosted.org/packages/77/58/22d5811b6103291584027de25b0775310e64ed032049a56580fc6ce42a17/devicehive-2.0.2.tar.gz" } ], "2.1.0": [ { "comment_text": "", "digests": { "md5": "56fa607c386675733c9e5718e8adcb69", "sha256": "e5709a0b068960c76b95e3212584b3b1b9b5a7a0ae8ebf18db0a6d69bb0db5cf" }, "downloads": -1, "filename": "devicehive-2.1.0.tar.gz", "has_sig": false, "md5_digest": "56fa607c386675733c9e5718e8adcb69", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 29421, "upload_time": "2017-10-12T14:59:31", "url": "https://files.pythonhosted.org/packages/ea/d1/9cb571d304630cb422b2c5be67c46566b801c06306db3079848fb4325ff2/devicehive-2.1.0.tar.gz" } ], "2.1.1": [ { "comment_text": "", "digests": { "md5": "8c24ef87c0a53fa139990f6fc1e1ed66", "sha256": "f8317168206175d8a5b9b6f4edf5260359c74731de3aa72746e4a444651986fc" }, "downloads": -1, "filename": "devicehive-2.1.1.tar.gz", "has_sig": false, "md5_digest": "8c24ef87c0a53fa139990f6fc1e1ed66", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 29459, "upload_time": "2017-11-22T11:25:16", "url": "https://files.pythonhosted.org/packages/72/6f/93206fd6c0baf8ba2f8bffd3e2de69b59278387bd7252a99cc89914d0dcc/devicehive-2.1.1.tar.gz" } ], "2.1.2": [ { "comment_text": "", "digests": { "md5": "ced7e5bf3a9fbdd1491078014bb84163", "sha256": "70270c1922d38d029e979d92e9a0d6040cba6840d13b4cd7529fc0a2d8dad3f4" }, "downloads": -1, "filename": "devicehive-2.1.2.tar.gz", "has_sig": false, "md5_digest": "ced7e5bf3a9fbdd1491078014bb84163", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 32281, "upload_time": "2018-01-19T14:55:08", "url": "https://files.pythonhosted.org/packages/b6/61/4abe6dd2331f2f7eeab9556857ffc965f8c5f5a75b7999ef443aaa254a01/devicehive-2.1.2.tar.gz" } ], "2.1.3": [ { "comment_text": "", "digests": { "md5": "72b1776af65cf138d0b4a551049093dd", "sha256": "c8fc4267555a4fd03dfb6d515a3b8f598416980f139bbe51812200e2efa73cc4" }, "downloads": -1, "filename": "devicehive-2.1.3.tar.gz", "has_sig": false, "md5_digest": "72b1776af65cf138d0b4a551049093dd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 32304, "upload_time": "2018-03-05T13:42:46", "url": "https://files.pythonhosted.org/packages/07/e1/ac46aac34a68f11bd5dbec68046c23f87e8010117f87a86eb890402d3632/devicehive-2.1.3.tar.gz" } ], "2.1.4": [ { "comment_text": "", "digests": { "md5": "0b91fd5e652b6e5066dc12f2f59f83df", "sha256": "fd263f396058f4c474831c2d53ee4ab86e1fdaedd22214d268b84e9c4220bba5" }, "downloads": -1, "filename": "devicehive-2.1.4.tar.gz", "has_sig": false, "md5_digest": "0b91fd5e652b6e5066dc12f2f59f83df", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 33822, "upload_time": "2018-06-05T10:45:28", "url": "https://files.pythonhosted.org/packages/14/1f/ab5107214945e1c7ccb3fd4ab64b1517b2c3d4f53aca896b03220f265649/devicehive-2.1.4.tar.gz" } ], "2.1.5": [ { "comment_text": "", "digests": { "md5": "8c2ca8844f30b510cfc6cc858b31f1a5", "sha256": "9ea76185b51fcb0dc36119799ae49515ddc5901cb2b1f0bdf63a3bccfe2fabb4" }, "downloads": -1, "filename": "devicehive-2.1.5.tar.gz", "has_sig": false, "md5_digest": "8c2ca8844f30b510cfc6cc858b31f1a5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 34173, "upload_time": "2018-06-18T09:35:17", "url": "https://files.pythonhosted.org/packages/4e/42/8f4c07dadf7001e9640436e105df1a44c2828e90a87f26e3f516592c47f5/devicehive-2.1.5.tar.gz" } ], "2.1.6": [ { "comment_text": "", "digests": { "md5": "7b313183bc8dd6b58dfeeeefd76d90b1", "sha256": "b53450dbd9e2dcd8e95fde552f09416ba63f88a72adcb705a02268b998d52fbb" }, "downloads": -1, "filename": "devicehive-2.1.6.tar.gz", "has_sig": false, "md5_digest": "7b313183bc8dd6b58dfeeeefd76d90b1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 34119, "upload_time": "2018-06-20T10:42:22", "url": "https://files.pythonhosted.org/packages/77/7c/b11d3f9e7397be9ead11a9bc5c9fd42de7a83a1d98693896f8d450353a3d/devicehive-2.1.6.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7b313183bc8dd6b58dfeeeefd76d90b1", "sha256": "b53450dbd9e2dcd8e95fde552f09416ba63f88a72adcb705a02268b998d52fbb" }, "downloads": -1, "filename": "devicehive-2.1.6.tar.gz", "has_sig": false, "md5_digest": "7b313183bc8dd6b58dfeeeefd76d90b1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 34119, "upload_time": "2018-06-20T10:42:22", "url": "https://files.pythonhosted.org/packages/77/7c/b11d3f9e7397be9ead11a9bc5c9fd42de7a83a1d98693896f8d450353a3d/devicehive-2.1.6.tar.gz" } ] }