uni-meter icon indicating copy to clipboard operation
uni-meter copied to clipboard

Shelly Pro 3EM / Pro EM emulation: missing RPC methods and error handling for unknown methods

Open andrebrait opened this issue 5 months ago • 1 comments

While working on the Shelly Pro EM output (#382), I compared the emulation against the RPC surface of a real Gen2 Shelly. A few gaps could make the emulation more robust against probing consumers. Listed by impact:

1. Unknown RPC methods are dropped instead of answered with an error

Rpc.parseRequest() throws for any method that is not in its switch (Rpc.treeToRequest()). The effect depends on the transport:

  • Websocket / UDP: the IllegalArgumentException is caught and logged at debug level — the client gets no response at all and runs into its timeout.
  • HTTP POST /rpc: the exception bubbles up as an HTTP 500 without a JSON RPC error frame.

A real device replies with {"error":{"code":404,"message":"No handler for <method>"}}. Returning that instead would make consumers that probe a few methods to fingerprint the device degrade gracefully. This is the single most valuable change because it covers every method nobody thought to stub.

Related: HTTP GET /rpc/<Method> is a hardcoded whitelist in HttpRoute, while a real Gen2 device dispatches any method via GET with query parameters. Routing unmatched GET /rpc/<method> requests into the same createRpcResponse() pipeline would close many small gaps at once.

2. Methods available via HTTP GET but not via JSON RPC

These work as GET /rpc/Temperature.GetStatus but fail when sent as JSON RPC over POST/websocket/UDP because they are missing from Rpc.treeToRequest() and createRpcResult():

  • Temperature.GetStatus / Temperature.GetConfig

Conversely, several components appear in the composite Shelly.GetStatus but are not individually callable at all (the request records already exist in Rpc.java, they are just never parsed):

  • BLE.GetConfig / BLE.GetStatus
  • Eth.GetStatus
  • Mqtt.GetStatus
  • Ws.GetStatus

3. Methods a real device has that are absent everywhere

Roughly in order of practical value:

Method Why it matters
Shelly.ListMethods Tools and some integrations use it for discovery; trivial stub.
Switch.GetStatus/GetConfig + switch:0 component (Pro EM only) The real Pro EM-50 has a relay; clients that validate the component list against the model may stumble on its absence from Shelly.GetComponents/GetStatus.
Sys.SetConfig, EM.SetConfig, EM1.SetConfig Apps that try to set a device name / CT type currently get an error; ack-and-ignore stubs match real behavior closely enough.
Shelly.CheckForUpdate The Shelly app and some integrations call it on connect; a stub returning {} (no updates) is accurate.
NotifyFullStatus on outbound websocket connect Home Assistant's aioshelly expects a full status push after connecting; the emulator only sends NotifyStatus deltas with em:0/em1:0. Matters only for the outbound websocket path.
EMData.GetRecords / EMData.GetData (history CSV) Used by the Shelly app's energy graphs and a few EMS. Would require storing history — significant effort, low value for storage-control use cases.
KVS.*, Schedule.*, Webhook.*, Mqtt.GetConfig Only the official app really touches these; empty-list stubs possible but low value.

Not worth doing in my opinion: Gen1-style endpoints beyond the existing /shelly and /settings — a real Pro 3EM / Pro EM is Gen2-only and does not serve /status, so adding it would make the emulation less faithful.

Suggested order: (1) "No handler" error frames on all transports, (2) generic GET /rpc/<method> dispatch, (3) the missing parse cases from section 2, (4) Shelly.ListMethods, (5) switch:0 on the Pro EM. Items 1–4 benefit both devices; item 5 is Pro EM fidelity.

Happy to contribute these as PRs if there is interest.


This analysis was produced together with Claude (Anthropic's AI coding assistant) by comparing the emulator's RPC dispatch code against the Shelly Gen2 API documentation.

andrebrait avatar Jun 12 '26 14:06 andrebrait

Subscribe to updates

stefan123t avatar Jun 22 '26 10:06 stefan123t