def test_device_notification_by_tuple(self): def callback(notification, data): pass n_index_group = 1 n_index_offset = 0 attr = NotificationAttrib(length=4) requests = self.test_server.request_history with self.plc: notification, user_hnl = self.plc.add_device_notification( (n_index_group, n_index_offset), attr, callback) # Assert that ADDDEVICENOTIFICATION was used to add device notification self.assert_command_id(requests[0], constants.ADSCOMMAND_ADDDEVICENOTE) # Delete notification without user-handle self.plc.del_device_notification(notification, None) # Create notification with user_handle notification, new_user_hnl = self.plc.add_device_notification( (n_index_group, n_index_offset), attr, callback, user_handle=user_hnl) self.assertEqual(new_user_hnl, user_hnl) # Assert that ADDDEVICENOTIFICATION was used to add device notification self.assert_command_id(requests[1], constants.ADSCOMMAND_DELDEVICENOTE) self.plc.del_device_notification(notification, None)
def test_device_notification_data_error(self): def callback(notification, data): pass attr = NotificationAttrib(length=4) with self.assertRaises(TypeError): ads.add_device_notification(self.endpoint, 0, attr, callback) with self.assertRaises(TypeError): ads.add_device_notification(self.endpoint, None, attr, callback)
def test_device_notification_by_name(self): def callback(notification, data): pass handle_name = "TestHandle" attr = NotificationAttrib(length=4) requests = self.test_server.request_history with self.plc: notification, user = self.plc.add_device_notification(handle_name, attr, callback) # Assert that Read/Write command was used to get the handle by name self.assert_command_id(requests[0], constants.ADSCOMMAND_READWRITE) # Assert that ADDDEVICENOTIFICATION was used to add device notification self.assert_command_id(requests[1], constants.ADSCOMMAND_ADDDEVICENOTE) self.plc.del_device_notification(notification, user) # Assert that ADDDEVICENOTIFICATION was used to add device notification self.assert_command_id(requests[2], constants.ADSCOMMAND_DELDEVICENOTE)
def test_device_notification(self): def callback(adr, notification, user): pass handle_name = 'TestHandle' attr = NotificationAttrib(length=4) requests = self.test_server.request_history notification, user = ads.add_device_notification( self.endpoint, handle_name, attr, callback) # Assert that Read/Write command was used to get the handle by name self.assert_command_id(requests[0], constants.ADSCOMMAND_READWRITE) # Assert that ADDDEVICENOTIFICATION was used to add device notification self.assert_command_id(requests[1], constants.ADSCOMMAND_ADDDEVICENOTE) ads.del_device_notification(self.endpoint, notification, user) # Assert that ADDDEVICENOTIFICATION was used to add device notification self.assert_command_id(requests[2], constants.ADSCOMMAND_DELDEVICENOTE)