Shelly.Account (Shelly v0.1.0)

Copy Markdown View Source

Account-level Shelly Cloud API, authorized by an OAuth access token (Authorization: Bearer) — no per-device auth keys needed.

An account here is a plain map (or any struct) with:

  • :server — the account's cloud server, e.g. "https://shelly-74-eu.shelly.cloud" (from Shelly.OAuth's user_api_url)
  • :token — the OAuth access token

All calls are paced through Shelly.RateGate when it is running (~1 request/second/account is the cloud's limit).

Summary

Functions

Status of every device on the account in ONE call (all_status). Returns {:ok, %{device_id => raw_status}} with lowercase ids; parse per device/channel with Shelly.Status.parse/4.

Flatten a list_devices/1 result into one entry per channel — multi-relay devices (Pro 2/3/4) become several addable rows.

List every device on the account (get_all_lists): id, user-given name, model/type, generation, channel count, room, online state.

Parse one device's all_statuses/1 entry for a channel — derives online from the payload's cloud connectivity instead of assuming it

Switch a relay channel on or off.

Types

account()

@type account() :: %{server: String.t(), token: String.t()}

Functions

all_statuses(account)

Status of every device on the account in ONE call (all_status). Returns {:ok, %{device_id => raw_status}} with lowercase ids; parse per device/channel with Shelly.Status.parse/4.

expand_channels(devices)

Flatten a list_devices/1 result into one entry per channel — multi-relay devices (Pro 2/3/4) become several addable rows.

list_devices(account)

List every device on the account (get_all_lists): id, user-given name, model/type, generation, channel count, room, online state.

Returns {:ok, devices} where devices is the raw map keyed by device id — see expand_channels/1 for a flattened per-channel list.

parse_status(raw_status, channel)

Parse one device's all_statuses/1 entry for a channel — derives online from the payload's cloud connectivity instead of assuming it:

{:ok, statuses} = Shelly.Account.all_statuses(account)
Shelly.Account.parse_status(statuses["0cdc7ef76644"], 0)

set_switch(account, device_id, channel, on?)

Switch a relay channel on or off.