How to use pyads - 10 common examples

To help you get started, we’ve selected a few pyads examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stlehmann / pyads / pyads / testserver.py View on Github external
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')
github stlehmann / pyads / pyads / testserver.py View on Github external
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'
github stlehmann / pyads / pyads / testserver_ex.py View on Github external
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:
github stlehmann / pyads / pyads / testserver_ex.py View on Github external
def handle_read_state():
            logger.info('Command received: READ_STATE')
            ads_state = struct.pack('
github stlehmann / pyads / pyads / testserver.py View on Github external
"""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
github stlehmann / pyads / pyads / testserver_ex.py View on Github external
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')
github stlehmann / pyads / pyads / testserver.py View on Github external
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'
github stlehmann / pyads / pyads / testserver_ex.py View on Github external
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')
github stlehmann / pyads / pyads / testserver.py View on Github external
def handle_request(self, request):
        # Extract command id from the request
        command_id_bytes = request.ams_header.command_id
        command_id = struct.unpack('