def test_get_and_set_resource_value(self): # an example: get and set a resource value from mbed_cloud.foundation import Device from mbed_cloud import ApiFilter from mbed_cloud.foundation.enums import DeviceStateEnum from mbed_cloud import ConnectAPI # Use the Foundation interface to find a registered device. api_filter = ApiFilter() api_filter.add_filter("state", "eq", DeviceStateEnum.REGISTERED) device = Device().list(max_results=2, filter=api_filter).next() # Use the Legacy interface to find resources connect_api = ConnectAPI() # Find an observable resource for resource in connect_api.list_resources(device.id): if resource.observable: break # Set a resource value connect_api.set_resource_value(device.id, resource.path, "12") # Get a resource value value = connect_api.get_resource_value(device.id, resource.path) print("Device %s, path %s, current value: %s" %(device.id, resource.path, value)) # end of example connect_api.stop_notifications()
def test_autostart_enabled(self): with mock.patch('urllib3.PoolManager.request') as mocked: mocked.return_value = mock.MagicMock() mocked.return_value.data = b'' mocked.return_value.status = 200 a = ConnectAPI(dict(autostart_notification_thread=True)) self.assertFalse(a.has_active_notification_thread) a.get_resource_value_async('abc123', '/3/4/5') self.assertTrue(a.has_active_notification_thread) a.stop_notifications()