(hass: HomeAssistant,
                               data: RequestData,
                               action: str,
                               message: dict[str, Any])
return {
        'request_id': data.request_id,
        'payload': result
    }
Handle incoming API messages.
Handle incoming API messages.
Handle incoming API messages .
async def async_handle_message(hass: HomeAssistant,
                               data: RequestData,
                               action: str,
                               message: dict[str, Any]) -> dict[str, Any]:
    """Handle incoming API messages."""
    handler = HANDLERS.get(action)

    if handler is None:
        _LOGGER.error(f'Handler not found for {action!r}')
        return {
            'request_id': data.request_id,
            'payload': {'error_code': ERR_INTERNAL_ERROR}
        }

    # noinspection PyBroadException
    try:
        result = await handler(hass, data, message)
    except SmartHomeError as err:
        _LOGGER.error('Handler error: %s %s', err.code, err.message)
        return {
            'request_id': data.request_id,
            'payload': {'error_code': err.code}
        }
    except Exception:
        _LOGGER.exception('Handler unexpected error')
        return {
            'request_id': data.request_id,
            'payload': {'error_code': ERR_INTERNAL_ERROR}
        }

    if result is None:
        return {'request_id': data.request_id}

    return {
        'request_id': data.request_id,
        'payload': result
    }
async def async_handle_message ( hass : HomeAssistant , data : RequestData , action : str , message : dict [ str , Any ] ) -> dict [ str , Any ] : handler = HANDLERS . get ( action ) if handler is None : _LOGGER . error ( f'Handler not found for {action!r}' ) return { 'request_id' : data . request_id , 'payload' : { 'error_code' : ERR_INTERNAL_ERROR } } # noinspection PyBroadException try : result = await handler ( hass , data , message ) except SmartHomeError as err : _LOGGER . error ( 'Handler error: %s %s' , err . code , err . message ) return { 'request_id' : data . request_id , 'payload' : { 'error_code' : err . code } } except Exception : _LOGGER . exception ( 'Handler unexpected error' ) return { 'request_id' : data . request_id , 'payload' : { 'error_code' : ERR_INTERNAL_ERROR } } if result is None : return { 'request_id' : data . request_id } return { 'request_id' : data . request_id , 'payload' : result }