{"record":{"id":"ceedee9bbf8d867e","repo":"AlexxIT/go2rtc","slug":"hass-wrong-response","errorCode":null,"errorMessage":"hass: wrong response","messagePattern":"hass: wrong response","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hass/api.go","lineNumber":74,"sourceCode":"\nfunc (a *API) ExchangeSDP(entityID, offer string) (string, error) {\n\tvar msg = map[string]any{\n\t\t\"id\":        1,\n\t\t\"type\":      \"camera/web_rtc_offer\",\n\t\t\"entity_id\": entityID,\n\t\t\"offer\":     offer,\n\t}\n\tif err := a.ws.WriteJSON(msg); err != nil {\n\t\treturn \"\", err\n\t}\n\n\tvar res ResponseOffer\n\tif err := a.ws.ReadJSON(&res); err != nil {\n\t\treturn \"\", err\n\t}\n\n\tif res.Type != \"result\" || !res.Success {\n\t\treturn \"\", errors.New(\"hass: wrong response\")\n\t}\n\n\treturn res.Result.Answer, nil\n}\n\nfunc (a *API) GetWebRTCEntities() (map[string]string, error) {\n\ts := `{\"id\":1,\"type\":\"get_states\"}`\n\tif err := a.ws.WriteMessage(websocket.TextMessage, []byte(s)); err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar res ResponseStates\n\tif err := a.ws.ReadJSON(&res); err != nil {\n\t\treturn nil, err\n\t}\n\tif res.Type != \"result\" || !res.Success {\n\t\treturn nil, errors.New(\"hass: wrong response\")\n\t}","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/hass/api.go#L56-L92","documentation":"hass.API.ExchangeSDP sends a WebRTC offer via the Home Assistant websocket and expects a result message with Success == true. If the response type is not \"result\" or Success is false, this generic error is returned — the actual failure reason is in the response the library discards.","triggerScenarios":"Requesting a WebRTC answer for a camera entity that does not exist, is offline, does not support web_rtc stream type, or when the command ID mismatches so an error message arrives instead of the result.","commonSituations":"Camera without WebRTC support (only HLS/LL-HLS); camera entity unavailable; camera integration erroring on offer; Home Assistant returning an error frame because the stream component rejected the SDP.","solutions":["Check that the target camera entity exists and supports the web_rtc frontend stream type.","Inspect Home Assistant logs for the underlying stream/camera error at the time of the request.","Confirm the camera integration is loaded and the entity state is not unavailable.","Improve the library call site to surface the raw response's error message for diagnosis."],"exampleFix":"// before\n// library discards res.Error\n// after\nif res.Type != \"result\" || !res.Success {\n    return \"\", fmt.Errorf(\"hass: wrong response: type=%s err=%v\", res.Type, res.Error)\n}","handlingStrategy":"validation","validationCode":"// verify camera supports WebRTC before exchanging SDP\nstates, err := api.GetWebRTCEntities()\nif err != nil { return err }\nif _, ok := states[cameraEntityID]; !ok {\n    return fmt.Errorf(\"camera %s does not support web_rtc\", cameraEntityID)\n}","typeGuard":null,"tryCatchPattern":"answer, err := api.ExchangeSDP(entityID, offer)\nif err != nil {\n    if strings.Contains(err.Error(), \"hass: wrong response\") {\n        return fmt.Errorf(\"camera rejected the WebRTC offer (unsupported stream type or entity offline): %w\", err)\n    }\n    return err\n}","preventionTips":["Filter cameras via GetWebRTCEntities before attempting ExchangeSDP.","Confirm the camera entity is available in Home Assistant before calls.","Check Home Assistant stream component logs when offers fail."],"tags":["home-assistant","webrtc","camera","websocket"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}