rshelly 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ca07a064003f9ff3a668a6843b5e1c744b3d8fc052a9f0e9f31cd59d692753c6
4
+ data.tar.gz: b99d16ede13379fe93b63276c39a05bb4a12348ee681abd674e71ac7f11a31e5
5
+ SHA512:
6
+ metadata.gz: 734fe0ff8bd8f94d3f307f6603c1bc35e809921b6ca27e08be93e73bd550b6bb33ebfd064c6c5bde03e4081c2c1f56f642a9a6317c606d9d773f3cb1c97a3cea
7
+ data.tar.gz: a671a41acbec14cc49b0d9c54c8417d8a44c7d4745543976f727cf23f4e12473186ad6b5a7e804da273e772084d9a7ec79252455821b816bcb265625d073952e
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [0.1.0] - 2026-09-02
6
+
7
+ ### Added
8
+
9
+ - Gen1 HTTP and Gen2+ RPC device clients.
10
+ - mDNS discovery on Linux and macOS.
11
+ - Concurrent IPv4 network scanning and verified discovery.
12
+ - Human-readable CLI output with optional JSON output.
13
+ - Device inspection, switch, meter, temperature, light, RGBW, firmware, reboot, Wi-Fi, MQTT, input, webhook, raw RPC, and raw Gen1 commands.
14
+ - Normalized device information across Shelly generations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jonas Egton
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,207 @@
1
+ # rshelly
2
+
3
+ The `rshelly` Ruby library and `shelly` command for managing Shelly devices on a local network.
4
+
5
+ This is an unofficial project and is not affiliated with or endorsed by Shelly Group.
6
+
7
+ The gem supports the two API families used by current Shelly devices:
8
+
9
+ - Gen1 HTTP endpoints such as `/shelly`, `/status`, `/settings`, `/relay/0`, `/meter/0`, and `/ota`.
10
+ - Gen2+ RPC methods such as `Shelly.GetStatus`, `Shelly.GetConfig`, `Switch.Set`, `RGBW.Set`, `Temperature.GetStatus`, `Input.SetConfig`, `Webhook.Create`, `MQTT.SetConfig`, and `Shelly.Update`.
11
+
12
+ The first target is practical management of local devices from scripts, cron jobs, and Rails apps. App-specific work such as InfluxDB writes, device name maps, and automation rules should live outside this gem.
13
+
14
+ ## Installation
15
+
16
+ Install the gem and its `shelly` command:
17
+
18
+ ```sh
19
+ gem install rshelly
20
+ ```
21
+
22
+ Or add it to a Bundler-managed project:
23
+
24
+ ```ruby
25
+ gem "rshelly"
26
+ ```
27
+
28
+ For local development builds:
29
+
30
+ ```sh
31
+ gem build rshelly.gemspec
32
+ gem install ./rshelly-0.1.0.gem
33
+ ```
34
+
35
+ During development:
36
+
37
+ ```sh
38
+ ruby -Ilib exe/shelly help
39
+ ```
40
+
41
+ ## Requirements
42
+
43
+ `rshelly` requires Ruby 3.1 or newer and supports Linux and macOS. Library operations and network scanning have no external runtime dependencies.
44
+
45
+ mDNS discovery uses `avahi-browse` on Linux and the built-in `dns-sd` command on macOS. On Linux, install the package providing `avahi-browse` if it is not already available. Devices with HTTP or RPC authentication enabled are not currently supported.
46
+
47
+ Detailed command help is available with either form:
48
+
49
+ ```sh
50
+ shelly help wifi
51
+ shelly scan --help
52
+ ```
53
+
54
+ ## CLI
55
+
56
+ The CLI prints human-readable output by default. Add `--json` when using the command from scripts or when you want the raw structured response.
57
+
58
+ Discovery:
59
+
60
+ ```sh
61
+ shelly discover
62
+ shelly discover --verify
63
+ shelly discover --verify --concurrency 64
64
+ shelly scan
65
+ shelly --timeout 0.5 scan 192.168.0.0/24 --concurrency 64
66
+ shelly --json scan 192.168.0.0/24
67
+ ```
68
+
69
+ Discovery uses `avahi-browse` when available, which is the normal Linux path. On macOS it uses `dns-sd`.
70
+ With `--verify`, discovered IPv4 devices are checked concurrently; the default is 32 HTTP requests at a time.
71
+ `scan` does not depend on mDNS. It probes each IPv4 address on the current network, or on a supplied CIDR, and reports hosts that answer like Shelly devices. This is useful for devices whose mDNS responder is not currently advertising.
72
+ The default command and HTTP timeout for discovery is 5 seconds. Use `--timeout` to tune it for faster or slower networks. External discovery commands receive one additional second to shut down cleanly.
73
+ Public discovery and scan results use string keys. Verified results include the original mDNS record under the string-keyed `"discovery"` field.
74
+
75
+ Inspection:
76
+
77
+ ```sh
78
+ shelly info 192.168.0.55
79
+ shelly status 192.168.0.55
80
+ shelly config 192.168.0.55
81
+ ```
82
+
83
+ Switch/relay control:
84
+
85
+ ```sh
86
+ shelly switch 192.168.0.54 get
87
+ shelly switch 192.168.0.54 on
88
+ shelly switch 192.168.0.54 off
89
+ shelly switch 192.168.0.54 toggle --id 0
90
+ ```
91
+
92
+ Meters and temperature:
93
+
94
+ ```sh
95
+ shelly meter 192.168.0.64
96
+ shelly temp 192.168.0.78 --id 100
97
+ ```
98
+
99
+ RGBW:
100
+
101
+ ```sh
102
+ shelly light 192.168.0.85 get --id 0
103
+ shelly rgbw 192.168.0.55 get
104
+ shelly rgbw 192.168.0.55 set --id 0 --on --white 120 --transition 3
105
+ shelly rgbw 192.168.0.55 set --id 0 --off
106
+ ```
107
+
108
+ Firmware:
109
+
110
+ ```sh
111
+ shelly update check 192.168.0.55
112
+ shelly update start 192.168.0.55
113
+ ```
114
+
115
+ Reboot:
116
+
117
+ ```sh
118
+ shelly reboot 192.168.0.55
119
+ ```
120
+
121
+ Wi-Fi migration:
122
+
123
+ ```sh
124
+ shelly wifi 192.168.0.55 secondary NewSSID 'new password'
125
+ shelly wifi 192.168.0.55 primary NewSSID 'new password' --ip 192.168.10.55
126
+ shelly wifi 192.168.0.55 primary NewSSID 'new password' --ip 192.168.10.55 --netmask 255.255.255.0 --gw 192.168.10.1 --dns 192.168.10.1
127
+ ```
128
+
129
+ `primary` maps to Gen2 `sta` and Gen1 `/settings/sta`; `secondary` maps to Gen2 `sta1` and Gen1 `/settings/sta1`. With `--ip`, the command uses static IPv4. If omitted, netmask defaults to `255.255.255.0`, gateway is derived as `.1` in the same `/24`, and DNS defaults to the gateway.
130
+
131
+ MQTT:
132
+
133
+ ```sh
134
+ shelly mqtt 192.168.0.55 192.168.0.10:1883
135
+ shelly mqtt 192.168.0.55 192.168.0.10:1883 --disable
136
+ ```
137
+
138
+ Input device setup, matching the current `input_setup.rb` workflow:
139
+
140
+ ```sh
141
+ shelly input setup 192.168.0.70 1 --base-url http://home.home/inputs
142
+ ```
143
+
144
+ That sets the device name to `input_device_1`, deletes existing webhooks, configures four inputs as buttons, and creates `push`, `longpush`, and `doublepush` webhooks for each input.
145
+
146
+ Escape hatches:
147
+
148
+ ```sh
149
+ shelly rpc 192.168.0.55 RGBW.GetStatus '{"id":0}'
150
+ shelly gen1 192.168.0.54 /relay/0 turn=on
151
+ ```
152
+
153
+ ## Ruby API
154
+
155
+ ```ruby
156
+ require "rshelly"
157
+
158
+ device = Shelly.client("192.168.0.55")
159
+ device.gen
160
+ device.normalized_info
161
+ device.status
162
+
163
+ device.switch_set(on: true)
164
+ device.meter_status
165
+ device.temperature_status(id: 100)
166
+ device.rgbw_set(id: 0, on: true, white: 120, transition_duration: 3)
167
+ device.update_info
168
+ device.set_wifi(slot: :secondary, ssid: "NewSSID", password: "new password")
169
+ device.set_wifi(slot: :primary, ssid: "NewSSID", password: "new password", ip: "192.168.10.55")
170
+ device.reboot
171
+ ```
172
+
173
+ When the generation is already known, pass it to avoid the initial `/shelly` request before a generation-specific operation:
174
+
175
+ ```ruby
176
+ device = Shelly.client("192.168.0.55", generation: 2, timeout: 0.5)
177
+ device.switch_set(on: true)
178
+ ```
179
+
180
+ Network, timeout, protocol, and TLS transport failures are raised as `Shelly::HttpError`. RPC error responses are raised as `Shelly::RpcError`.
181
+
182
+ Discovery:
183
+
184
+ ```ruby
185
+ Shelly.discover
186
+ Shelly.discover(verify: true)
187
+ Shelly.discover(verify: true, concurrency: 64)
188
+ Shelly.scan
189
+ Shelly.scan(network: "192.168.0.0/24", timeout: 0.5, concurrency: 64)
190
+ ```
191
+
192
+ Low-level calls:
193
+
194
+ ```ruby
195
+ device.get_json("/relay/0", turn: "off")
196
+ device.rpc("Switch.Set", id: 0, on: false)
197
+ ```
198
+
199
+ ## Development
200
+
201
+ Install development dependencies, run the tests, and build the gem:
202
+
203
+ ```sh
204
+ bundle install
205
+ bundle exec rake test
206
+ bundle exec rake build
207
+ ```
data/exe/shelly ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
5
+
6
+ require "rshelly/cli"
7
+
8
+ exit Shelly::CLI.new(ARGV).run