The transport every other module is built on.
call/5 can reach any method on any service, including ones this library has no
typed wrapper for, so a missing convenience function is never a dead end:
Bravia.RPC.call(tv, "video", "getPictureQualitySettings", [%{"target" => ""}])Why this is not a thin wrapper over Req
Two BRAVIA behaviours make a naive HTTP client wrong, and both are handled here.
Sony reports application errors with an HTTP 200 status and an "error" array
in the body, so the status code alone never tells you whether a call worked.
Successful responses put their payload under "result" for most methods but
"results" for others — getMethodTypes among them. Both are accepted.
Return values
Sony always wraps a result in an array of return values. Where that array holds
exactly one value, call/5 unwraps it, because virtually every method returns one
thing and the extra layer is pure noise. Arrays with any other number of elements
come back as-is.
# "result": [{"status": "active"}]
{:ok, %{"status" => "active"}}
# "result": [[{"target" => "speaker", ...}]]
{:ok, [%{"target" => "speaker", ...}]}
Summary
Functions
Invokes method on service.
Invokes a method whose result carries no information, returning :ok.
Functions
@spec call(Bravia.Client.t(), String.t(), String.t(), list(), String.t()) :: {:ok, term()} | {:error, Bravia.Error.t()}
Invokes method on service.
params is Sony's positional parameter array — usually a single map, or an empty
list. version must be one the television supports for that method; they differ
between models, so check Bravia.capabilities/1 when in doubt.
@spec command(Bravia.Client.t(), String.t(), String.t(), list(), String.t()) :: :ok | {:error, Bravia.Error.t()}
Invokes a method whose result carries no information, returning :ok.
Sony's setters answer with an empty result array. Surfacing that as {:ok, []} at
every call site adds nothing, so writes use this instead.