everlights 0.1.0 → 0.2.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 +4 -4
- data/README.md +20 -1
- data/exe/everlights +17 -3
- data/lib/everlights/sync.rb +28 -9
- data/lib/everlights/web.html +854 -0
- data/lib/everlights/web.rb +206 -0
- data/lib/everlights.rb +19 -0
- data/skills/everlights/SKILL.md +4 -2
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0d319ee1f69ecca30fa28e49bac2a468bb9f069d9f438d6d7ca6bc5e20adb1ed
|
|
4
|
+
data.tar.gz: 427cd966f9b74e8c158db2847862ea7d739e064cfac5b0e3b418ce797f657cf4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ea88456723a18232c6aaf93ff903dfd050cb4054eb2bd97eb782cc13dc9bb227198d5efac12510553e37e692a798d06731df53f0a19d9fcd14a23a62926a0dc2
|
|
7
|
+
data.tar.gz: 197bbe6f6247cd149164cfd5785ac1e86aeca84570dc4ce9c770ac35fcdcce05d34d0f6eae9e46293438ab920fec3a8f13f829ea2de60ff7a6d18aa5b84476c0
|
data/README.md
CHANGED
|
@@ -26,6 +26,7 @@ Requires Ruby 3.1+.
|
|
|
26
26
|
|
|
27
27
|
```sh
|
|
28
28
|
everlights bridge # firmware, network, cloud, zone health
|
|
29
|
+
everlights bridge health # ok/WARN checks; exits 2 on any warning
|
|
29
30
|
everlights show # what's playing, e.g. "Halloween Fade (Halloween show)"
|
|
30
31
|
|
|
31
32
|
everlights play "Hallows Eve" # a saved sequence, now
|
|
@@ -86,9 +87,25 @@ schedule: # higher in the list wins a shared night
|
|
|
86
87
|
- **Config location:** `--config` or `$EVERLIGHTS_CONFIG`. The config's `bridge.host` is used by every command unless `--host` or `$EVERLIGHTS_HOST` is set.
|
|
87
88
|
- **Time zone:** set `timezone:` in the config, or it uses your machine's.
|
|
88
89
|
|
|
90
|
+
### In a browser
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
everlights web # http://localhost:4567 (--port to change)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The **Calendar** view shows each night ahead as a bulb on a light string, lit with the sequence that plays. Drag rules to set their priority. Drag sequences onto rules, or between them. Rule changes are saved to the config file straight away.
|
|
97
|
+
|
|
98
|
+
Hover any sequence chip to open its card. For your own sequences you can edit colors and effects there, then **Save** or **Revert**. Built-ins and app-made sequences can be previewed or copied into yours. The **Sequences** view has the same editor for all of your sequences. The **Bridge** view shows health checks (the same as `bridge health`), firmware, network, reboots, and each zone's signal and sensors. It has buttons to set the clock and to reboot; reboot asks you to click twice. **Apply** sends the pending changes to the bridge.
|
|
99
|
+
|
|
100
|
+
**Preview** (on a sequence, or click a bridge sequence) shows it on the lights now, and edits to it show as you make them. **Stop preview** hands the lights back to the calendar. So does closing the page: the preview is cleared about 20 seconds after the page stops checking in, and also when the server quits. During a running show, a preview only lasts until the show's next sequence change.
|
|
101
|
+
|
|
102
|
+
The page only listens on localhost. Saving rewrites the YAML, which drops your comments; the first save keeps the original at `everlights.yml.bak`, and that copy is never replaced. If you edit the file by hand while the page is open, the page reloads it instead of overwriting it.
|
|
103
|
+
|
|
89
104
|
To keep the calendar topped up, run it on a schedule, for example monthly from cron:
|
|
90
105
|
`0 9 1 * * cd ~/everlights && everlights sync >> config/sync.log 2>&1`
|
|
91
106
|
|
|
107
|
+
To only be told when it needs a sync, use `everlights sync --check`. It prints the plan and changes nothing. It exits 0 when the bridge matches the config, 2 when it needs a sync, and 1 on an error.
|
|
108
|
+
|
|
92
109
|
## Ruby
|
|
93
110
|
|
|
94
111
|
```ruby
|
|
@@ -161,7 +178,9 @@ Observed on the bridge (`ruby -Ilib test/live_check.rb` repeats the round trip):
|
|
|
161
178
|
ruby -Ilib -e 'Dir["test/*_test.rb"].each { require "./#{_1}" }'
|
|
162
179
|
```
|
|
163
180
|
|
|
164
|
-
The tests run against a fake bridge, so no hardware is needed.
|
|
181
|
+
The tests run against a fake bridge, so no hardware is needed. CI runs them on every push and pull request.
|
|
182
|
+
|
|
183
|
+
To release, bump the version in `everlights.gemspec`, commit, then tag and push (`git tag v0.2.0 && git push origin v0.2.0`). The release workflow tests, then publishes to RubyGems and GitHub Packages and creates a GitHub release with the `.gem` attached.
|
|
165
184
|
|
|
166
185
|
## Credits
|
|
167
186
|
|
data/exe/everlights
CHANGED
|
@@ -7,6 +7,7 @@ USAGE = <<~TXT
|
|
|
7
7
|
|
|
8
8
|
Bridge:
|
|
9
9
|
bridge firmware, network, cloud, zone health
|
|
10
|
+
bridge health ok/WARN per check; exit 2 on any warning (for cron)
|
|
10
11
|
bridge time [TIME] set the bridge clock (default now)
|
|
11
12
|
bridge reboot --yes restart the bridge
|
|
12
13
|
zones raw zone data (JSON)
|
|
@@ -32,6 +33,8 @@ USAGE = <<~TXT
|
|
|
32
33
|
|
|
33
34
|
Sync (config/everlights.yml: sequences + schedule, see config/everlights.example.yml):
|
|
34
35
|
sync [--dry-run] [--adopt] build sequences and the calendar ahead; prints the plan
|
|
36
|
+
sync --check plan only; exit 2 if the bridge needs a sync (for cron)
|
|
37
|
+
web [--port N] edit the config in a browser and apply it (localhost:4567)
|
|
35
38
|
|
|
36
39
|
Options:
|
|
37
40
|
TXT
|
|
@@ -53,6 +56,8 @@ parser = OptionParser.new do |o|
|
|
|
53
56
|
o.on("--json", "JSON output for lists, show and bridge") { opts[:json] = true }
|
|
54
57
|
o.on("--yes", "confirm bridge reboot") { opts[:yes] = true }
|
|
55
58
|
o.on("--dry-run", "sync: print the plan only") { opts[:dry_run] = true }
|
|
59
|
+
o.on("--check", "sync: plan only, exit 2 if anything would change") { opts[:check] = true }
|
|
60
|
+
o.on("--port N", Integer, "web: port (default 4567)") { opts[:port] = _1 }
|
|
56
61
|
o.on("--adopt", "sync: take over bridge items whose names match the config") { opts[:adopt] = true }
|
|
57
62
|
end
|
|
58
63
|
parser.parse!
|
|
@@ -70,7 +75,7 @@ begin
|
|
|
70
75
|
zones = opts[:zones]
|
|
71
76
|
cmd = ARGV.shift
|
|
72
77
|
cmd = "#{cmd} #{ARGV.shift}" if %w[sequence calendar].include?(cmd) ||
|
|
73
|
-
(cmd == "bridge" && %w[time reboot].include?(ARGV.first))
|
|
78
|
+
(cmd == "bridge" && %w[health time reboot].include?(ARGV.first))
|
|
74
79
|
arg = ARGV.join(" ")
|
|
75
80
|
|
|
76
81
|
case cmd
|
|
@@ -91,6 +96,10 @@ begin
|
|
|
91
96
|
puts " last request #{at.(z["lastRequestDate"])}, response #{at.(z["lastResponseDate"])}, reboots #{z["rebootCount"]}"
|
|
92
97
|
end
|
|
93
98
|
end
|
|
99
|
+
when "bridge health"
|
|
100
|
+
checks = Everlights.health(el.status)
|
|
101
|
+
checks.each { |ok, name, text| puts "#{{info: "info", true => "ok ", false => "WARN"}[ok]} #{name.ljust(19)} #{text}" }
|
|
102
|
+
exit 2 unless checks.all? { _1[0] }
|
|
94
103
|
when "bridge time"
|
|
95
104
|
time = ARGV.empty? ? Time.now : Time.parse(arg)
|
|
96
105
|
el.set_time(time)
|
|
@@ -175,16 +184,21 @@ begin
|
|
|
175
184
|
|
|
176
185
|
when "sync"
|
|
177
186
|
raise Everlights::Error, "no config at #{config_path}; copy config/everlights.example.yml to start" unless config
|
|
178
|
-
|
|
179
|
-
plan = Everlights::Sync.new(el, config, state_path: state_path, adopt: opts[:adopt]).plan
|
|
187
|
+
plan = Everlights::Sync.new(el, config, state_path: Everlights::Sync.state_path(config_path), adopt: opts[:adopt]).plan
|
|
180
188
|
puts plan
|
|
181
189
|
if plan.empty? then nil
|
|
190
|
+
elsif opts[:check] then exit 2
|
|
182
191
|
elsif opts[:dry_run] then puts "\n(dry run: nothing applied)"
|
|
183
192
|
else
|
|
184
193
|
plan.apply!
|
|
185
194
|
puts "\nApplied."
|
|
186
195
|
end
|
|
187
196
|
|
|
197
|
+
when "web"
|
|
198
|
+
raise Everlights::Error, "no config at #{config_path}; copy config/everlights.example.yml to start" unless config
|
|
199
|
+
require_relative "../lib/everlights/web"
|
|
200
|
+
Everlights::Web.new(el, config_path, port: opts[:port] || 4567).start
|
|
201
|
+
|
|
188
202
|
else abort parser.help
|
|
189
203
|
end
|
|
190
204
|
rescue Everlights::Error, IndexError, ArgumentError, TypeError, Date::Error, SystemCallError, Net::OpenTimeout => e
|
data/lib/everlights/sync.rb
CHANGED
|
@@ -19,7 +19,8 @@ module Everlights
|
|
|
19
19
|
|
|
20
20
|
Action = Struct.new(:kind, :op, :name, :detail, :run)
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
# shows: {rule name => [[start, end], ...]}, the nights each rule plays, tonight's show under way included
|
|
23
|
+
Plan = Struct.new(:actions, :skips, :horizon, :sync, :shows) do
|
|
23
24
|
def empty? = actions.empty?
|
|
24
25
|
def apply! = sync.apply(self)
|
|
25
26
|
|
|
@@ -33,32 +34,48 @@ module Everlights
|
|
|
33
34
|
rows.each { |a| out << " #{mark[a.op]} #{a.op.to_s.ljust(7)} #{a.name}#{": #{a.detail}" if a.detail}" }
|
|
34
35
|
end
|
|
35
36
|
lost, other = skips.partition { |_, _, why| why.end_with?(" wins this night") }
|
|
37
|
+
dark, other = other.partition { |_, _, why| why.start_with?("dusk (") }
|
|
36
38
|
unless other.empty?
|
|
37
39
|
out << "Skipped"
|
|
38
40
|
other.each { |d, rule, why| out << " #{d.strftime("%a %Y-%m-%d")} #{rule}: #{why}" }
|
|
39
41
|
end
|
|
42
|
+
unless dark.empty?
|
|
43
|
+
out << "No show: dusk is after the end time"
|
|
44
|
+
dark.group_by { _2 }.each do |rule, rows|
|
|
45
|
+
out << " #{rule}: #{nights(rows.map(&:first))} (dusk up to #{rows.map { _3[/\d\d:\d\d/] }.max}, ends #{rows[0][2][/(\d\d:\d\d) end/, 1]})"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
40
48
|
unless lost.empty?
|
|
41
49
|
out << "Nights taken by a higher rule"
|
|
42
50
|
lost.group_by { |_, rule, why| [rule, why.delete_suffix(" wins this night")] }.each do |(rule, winner), rows|
|
|
43
|
-
|
|
44
|
-
span = days.size == 1 ? days[0].strftime("%b %-d") : "#{days[0].strftime("%b %-d")} – #{days[-1].strftime("%b %-d")}"
|
|
45
|
-
out << " #{rule}: #{days.size} night#{"s" unless days.size == 1} to #{winner} (#{span})"
|
|
51
|
+
out << " #{rule}: #{nights(rows.map(&:first)).sub(", ", " to #{winner} (")})"
|
|
46
52
|
end
|
|
47
53
|
end
|
|
48
54
|
out << "Nothing to change." if empty?
|
|
49
55
|
out.join("\n")
|
|
50
56
|
end
|
|
57
|
+
|
|
58
|
+
def nights(days) # "3 nights, Jun 26 – Jun 28"
|
|
59
|
+
span = days.size == 1 ? days[0].strftime("%b %-d") : "#{days[0].strftime("%b %-d")} – #{days[-1].strftime("%b %-d")}"
|
|
60
|
+
"#{days.size} night#{"s" unless days.size == 1}, #{span}"
|
|
61
|
+
end
|
|
51
62
|
end
|
|
52
63
|
|
|
53
64
|
def self.load_config(path)
|
|
54
65
|
config = YAML.safe_load_file(path, permitted_classes: [Date]) || {}
|
|
55
66
|
# YAML 1.1 reads the key `on:` as boolean true; put it back
|
|
56
|
-
|
|
67
|
+
# (transform_keys keeps `on` where it was, so a saved file reads in the same order)
|
|
68
|
+
config["schedule"].map! { |r| r.is_a?(Hash) ? r.transform_keys { _1 == true ? "on" : _1 } : r } if config["schedule"].is_a?(Array)
|
|
57
69
|
config
|
|
58
70
|
rescue Psych::SyntaxError => e
|
|
59
71
|
raise Error, "#{path}: #{e.message}"
|
|
60
72
|
end
|
|
61
73
|
|
|
74
|
+
# What sync has made on the bridge, next to the config.
|
|
75
|
+
def self.state_path(config_path) = File.join(File.dirname(config_path), ".sync-state.yml")
|
|
76
|
+
|
|
77
|
+
attr_reader :bridge_seqs # the bridge's sequences, as read by the last #plan
|
|
78
|
+
|
|
62
79
|
def initialize(client, config, state_path: nil, adopt: false, now: Time.now)
|
|
63
80
|
@c, @cfg, @state_path, @adopt, @now = client, config || {}, state_path, adopt, now
|
|
64
81
|
end
|
|
@@ -66,7 +83,7 @@ module Everlights
|
|
|
66
83
|
def plan
|
|
67
84
|
@errors = []
|
|
68
85
|
@state = load_state
|
|
69
|
-
bridge_seqs = @c.sequence_list
|
|
86
|
+
bridge_seqs = @bridge_seqs = @c.sequence_list
|
|
70
87
|
bridge_events = @c.event_list
|
|
71
88
|
actions = @adopt ? adopt(bridge_seqs, bridge_events) : []
|
|
72
89
|
owned_seq_ids = @state["sequences"].values
|
|
@@ -128,7 +145,7 @@ module Everlights
|
|
|
128
145
|
losers.each { skips << [d, _1[:name], "#{winner[:name]} wins this night"] }
|
|
129
146
|
s, e = window(winner, d)
|
|
130
147
|
if e.nil?
|
|
131
|
-
skips << [d, winner[:name], "dusk (#{s.strftime("%H:%M")}) is after its end
|
|
148
|
+
skips << [d, winner[:name], "dusk (#{s.strftime("%H:%M")}) is after its #{format("%02d:%02d", *winner[:end])} end"]
|
|
132
149
|
elsif s <= @now + MARGIN
|
|
133
150
|
skips << [d, winner[:name], "already started or starts within 15 minutes"]
|
|
134
151
|
elsif (other = others.find { |_, os, oe| os < e && s < oe })
|
|
@@ -140,11 +157,13 @@ module Everlights
|
|
|
140
157
|
|
|
141
158
|
# One calendar entry per rule. Nights already under way stay; ended ones are dropped.
|
|
142
159
|
live = ->(event) { event["occurrences"].select { |o| Time.parse(o["start"]) <= @now + MARGIN && Time.parse(o["end"]) > @now } }
|
|
160
|
+
shows = {}
|
|
143
161
|
rules.each do |r|
|
|
144
162
|
nights = wanted[r[:name]]
|
|
145
163
|
current = bridge_events.find { _1["id"] == @state["events"][r[:name]] }
|
|
146
|
-
kept = current ? live.(current).map { [Time.parse(_1["start"]), Time.parse(_1["end"])] } : []
|
|
164
|
+
kept = current ? live.(current).map { [Time.parse(_1["start"]).localtime, Time.parse(_1["end"]).localtime] } : []
|
|
147
165
|
occurrences = kept + nights
|
|
166
|
+
shows[r[:name]] = occurrences unless occurrences.empty?
|
|
148
167
|
flags = r[:start][:dusk] ? ["StartAtDusk"] : []
|
|
149
168
|
if current.nil?
|
|
150
169
|
next if nights.empty?
|
|
@@ -193,7 +212,7 @@ module Everlights
|
|
|
193
212
|
end
|
|
194
213
|
end
|
|
195
214
|
|
|
196
|
-
Plan.new(actions, skips, horizon, self)
|
|
215
|
+
Plan.new(actions, skips, horizon, self, shows)
|
|
197
216
|
end
|
|
198
217
|
|
|
199
218
|
def apply(plan)
|