Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def handle_devicenote():
logger.info('Command received: DEVICE_NOTIFICATION')
# No response data required
return b''
# Function map
function_map = {
constants.ADSCOMMAND_READDEVICEINFO: handle_read_device_info,
constants.ADSCOMMAND_READ: handle_read,
constants.ADSCOMMAND_WRITE: handle_write,
constants.ADSCOMMAND_READWRITE: handle_read_write,
constants.ADSCOMMAND_READSTATE: handle_read_state,
constants.ADSCOMMAND_WRITECTRL: handle_writectrl,
constants.ADSCOMMAND_ADDDEVICENOTE: handle_add_devicenote,
constants.ADSCOMMAND_DELDEVICENOTE: handle_delete_devicenote,
constants.ADSCOMMAND_DEVICENOTE: handle_devicenote,
}
# Try to map the command id to a function, else return error code
try:
response_content = function_map[command_id]()
except KeyError:
logger.info('Unknown Command: {0}'.format(hex(command_id)))
# Set error code to 'unknown command ID'
error_code = '\x08\x00\x00\x00'.encode('utf-8')
return AmsResponseData(state, error_code, ''.encode('utf-8'))
# Set no error in response
error_code = ('\x00' * 4).encode('utf-8')
logger.info("Command received: DELETE_DEVICE_NOTIFICATION")
# No response data required
return b""
def handle_devicenote():
# type: () -> bytes
"""Handle a device notification."""
logger.info("Command received: DEVICE_NOTIFICATION")
# No response data required
return b""
# Function map
function_map = {
constants.ADSCOMMAND_READDEVICEINFO: handle_read_device_info,
constants.ADSCOMMAND_READ: handle_read,
constants.ADSCOMMAND_WRITE: handle_write,
constants.ADSCOMMAND_READWRITE: handle_read_write,
constants.ADSCOMMAND_READSTATE: handle_read_state,
constants.ADSCOMMAND_WRITECTRL: handle_writectrl,
constants.ADSCOMMAND_ADDDEVICENOTE: handle_add_devicenote,
constants.ADSCOMMAND_DELDEVICENOTE: handle_delete_devicenote,
constants.ADSCOMMAND_DEVICENOTE: handle_devicenote,
}
# Try to map the command id to a function, else return error code
try:
response_content = function_map[command_id]()
except KeyError:
logger.info("Unknown Command: {0}".format(hex(command_id)))
# Set error code to 'unknown command ID'
index_group = struct.unpack("
handle = ('\x0F' * 4).encode('utf-8')
return handle
def handle_delete_devicenote():
logger.info('Command received: DELETE_DEVICE_NOTIFICATION')
# No response data required
return b''
def handle_devicenote():
logger.info('Command received: DEVICE_NOTIFICATION')
# No response data required
return b''
# Function map
function_map = {
constants.ADSCOMMAND_READDEVICEINFO: handle_read_device_info,
constants.ADSCOMMAND_READ: handle_read,
constants.ADSCOMMAND_WRITE: handle_write,
constants.ADSCOMMAND_READWRITE: handle_read_write,
constants.ADSCOMMAND_READSTATE: handle_read_state,
constants.ADSCOMMAND_WRITECTRL: handle_writectrl,
constants.ADSCOMMAND_ADDDEVICENOTE: handle_add_devicenote,
constants.ADSCOMMAND_DELDEVICENOTE: handle_delete_devicenote,
constants.ADSCOMMAND_DEVICENOTE: handle_devicenote,
}
# Try to map the command id to a function, else return error code
try:
response_content = function_map[command_id]()
except KeyError:
def handle_read_state():
logger.info('Command received: READ_STATE')
ads_state = struct.pack('
"""Handle a device notification."""
logger.info("Command received: DEVICE_NOTIFICATION")
# No response data required
return b""
# Function map
function_map = {
constants.ADSCOMMAND_READDEVICEINFO: handle_read_device_info,
constants.ADSCOMMAND_READ: handle_read,
constants.ADSCOMMAND_WRITE: handle_write,
constants.ADSCOMMAND_READWRITE: handle_read_write,
constants.ADSCOMMAND_READSTATE: handle_read_state,
constants.ADSCOMMAND_WRITECTRL: handle_writectrl,
constants.ADSCOMMAND_ADDDEVICENOTE: handle_add_devicenote,
constants.ADSCOMMAND_DELDEVICENOTE: handle_delete_devicenote,
constants.ADSCOMMAND_DEVICENOTE: handle_devicenote,
}
# Try to map the command id to a function, else return error code
try:
response_content = function_map[command_id]()
except KeyError:
logger.info("Unknown Command: {0}".format(hex(command_id)))
# Set error code to 'unknown command ID'
error_code = "\x08\x00\x00\x00".encode("utf-8")
return AmsResponseData(state, error_code, "".encode("utf-8"))
# Set no error in response
error_code = ("\x00" * 4).encode("utf-8")
response_data = error_code + response_content
def handle_devicenote():
logger.info('Command received: DEVICE_NOTIFICATION')
# No response data required
return b''
# Function map
function_map = {
constants.ADSCOMMAND_READDEVICEINFO: handle_read_device_info,
constants.ADSCOMMAND_READ: handle_read,
constants.ADSCOMMAND_WRITE: handle_write,
constants.ADSCOMMAND_READWRITE: handle_read_write,
constants.ADSCOMMAND_READSTATE: handle_read_state,
constants.ADSCOMMAND_WRITECTRL: handle_writectrl,
constants.ADSCOMMAND_ADDDEVICENOTE: handle_add_devicenote,
constants.ADSCOMMAND_DELDEVICENOTE: handle_delete_devicenote,
constants.ADSCOMMAND_DEVICENOTE: handle_devicenote,
}
# Try to map the command id to a function, else return error code
try:
response_content = function_map[command_id]()
except KeyError:
logger.info('Unknown Command: {0}'.format(hex(command_id)))
# Set error code to 'unknown command ID'
error_code = '\x08\x00\x00\x00'.encode('utf-8')
return AmsResponseData(state, error_code, ''.encode('utf-8'))
# Set no error in response
error_code = ('\x00' * 4).encode('utf-8')
def handle_delete_devicenote():
logger.info('Command received: DELETE_DEVICE_NOTIFICATION')
# No response data required
return b''
def handle_devicenote():
logger.info('Command received: DEVICE_NOTIFICATION')
# No response data required
return b''
# Function map
function_map = {
constants.ADSCOMMAND_READDEVICEINFO: handle_read_device_info,
constants.ADSCOMMAND_READ: handle_read,
constants.ADSCOMMAND_WRITE: handle_write,
constants.ADSCOMMAND_READWRITE: handle_read_write,
constants.ADSCOMMAND_READSTATE: handle_read_state,
constants.ADSCOMMAND_WRITECTRL: handle_writectrl,
constants.ADSCOMMAND_ADDDEVICENOTE: handle_add_devicenote,
constants.ADSCOMMAND_DELDEVICENOTE: handle_delete_devicenote,
constants.ADSCOMMAND_DEVICENOTE: handle_devicenote,
}
# Try to map the command id to a function, else return error code
try:
response_content = function_map[command_id]()
except KeyError:
logger.info('Unknown Command: {0}'.format(hex(command_id)))
# Set error code to 'unknown command ID'
def handle_delete_devicenote():
logger.info('Command received: DELETE_DEVICE_NOTIFICATION')
# No response data required
return b''
def handle_devicenote():
logger.info('Command received: DEVICE_NOTIFICATION')
# No response data required
return b''
# Function map
function_map = {
constants.ADSCOMMAND_READDEVICEINFO: handle_read_device_info,
constants.ADSCOMMAND_READ: handle_read,
constants.ADSCOMMAND_WRITE: handle_write,
constants.ADSCOMMAND_READWRITE: handle_read_write,
constants.ADSCOMMAND_READSTATE: handle_read_state,
constants.ADSCOMMAND_WRITECTRL: handle_writectrl,
constants.ADSCOMMAND_ADDDEVICENOTE: handle_add_devicenote,
constants.ADSCOMMAND_DELDEVICENOTE: handle_delete_devicenote,
constants.ADSCOMMAND_DEVICENOTE: handle_devicenote,
}
# Try to map the command id to a function, else return error code
try:
response_content = function_map[command_id]()
except KeyError:
logger.info('Unknown Command: {0}'.format(hex(command_id)))
# Set error code to 'unknown command ID'
error_code = '\x08\x00\x00\x00'.encode('utf-8')
def handle_request(self, request):
# Extract command id from the request
command_id_bytes = request.ams_header.command_id
command_id = struct.unpack('