Parse response into an instance of the appropriate child class.

def parse(text) -> Optional['Response']:
        """Parse response into an instance of the appropriate child class."""

        # Trim the start and end markers, and ensure only lowercase is used
        if text.startswith(MARKER_START) and text.endswith(MARKER_END):
            text = text[1:len(text)-1].lower()

        # No-op; can just ignore these
        if not text:
            return None

        if text.startswith(CMD_DATETIME):
            return DateTimeResponse(text)

        elif text.startswith(CMD_OPMODE):
            return OpModeResponse(text)

        elif text.startswith(CMD_DEVBYIDX_PREFIX):
            if RESPONSE_ERROR == text[2:] or text[2:4] == '00':
                return DeviceNotFoundResponse(text)
            return DeviceInfoResponse(text)

        elif text.startswith(CMD_DEVICE_PREFIX):
            action = next((a for a in [ACTION_ADD, ACTION_DEL, ACTION_SET]
                           if a == text[2:3]), ACTION_NONE)
            args = text[2+len(action):]
            if RESPONSE_ERROR == args:
                return DeviceNotFoundResponse(text)
            elif action == ACTION_ADD:
                if not args:
                    return DeviceAddingResponse(text)
                return DeviceAddedResponse(text)
            elif action == ACTION_SET:
                return DeviceChangedResponse(text)
            elif action == ACTION_DEL:
                return DeviceDeletedResponse(text)
            else:
                return DeviceInfoResponse(text)

        elif text.startswith(CMD_CLEAR_STATUS):
            return ClearedStatusResponse(text)

        elif text.startswith(CMD_ROMVER):
            return ROMVersionResponse(text)

        elif text.startswith(CMD_EXIT_DELAY):
            return ExitDelayResponse(text)

        elif text.startswith(CMD_ENTRY_DELAY):
            return EntryDelayResponse(text)

        elif text.startswith(CMD_SWITCH_PREFIX) and is_ascii_hex(text[1:2]):
            return SwitchResponse(text)

        elif text.startswith(CMD_EVENT_LOG):
            if RESPONSE_ERROR == text[2:]:
                return EventLogNotFoundResponse(text)
            return EventLogResponse(text)

        elif text.startswith(CMD_SENSOR_LOG):
            if RESPONSE_ERROR == text[2:]:
                return SensorLogNotFoundResponse(text)
            return SensorLogResponse(text)

        else:
            raise ValueError("Response not recognised: " + text)