everlights 0.1.1 → 1.0.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 +43 -7
- data/config/everlights.example.yml +105 -0
- data/exe/everlights +75 -26
- data/lib/everlights/cloud.rb +113 -0
- data/lib/everlights/sync.rb +93 -10
- data/lib/everlights/web.html +869 -0
- data/lib/everlights/web.rb +214 -0
- data/lib/everlights.rb +81 -10
- data/skills/everlights/SKILL.md +8 -5
- metadata +11 -5
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
require "socket"
|
|
2
|
+
require "io/wait"
|
|
3
|
+
require "json"
|
|
4
|
+
require "digest"
|
|
5
|
+
require "fileutils"
|
|
6
|
+
require_relative "../everlights"
|
|
7
|
+
|
|
8
|
+
module Everlights
|
|
9
|
+
# `everlights web`: a page on localhost for editing the sync config and applying it.
|
|
10
|
+
# GET / the page
|
|
11
|
+
# GET /api/state config and its version, bridge sequences, the night-by-night schedule, the plan
|
|
12
|
+
# PUT /api/config save the whole config (JSON) to the YAML file, then GET /api/state. Send If-Match: <version>
|
|
13
|
+
# and a file edited since then is left alone: 412, with the state as it is on disk.
|
|
14
|
+
# POST /api/apply run the plan against the bridge
|
|
15
|
+
# GET /api/bridge status, health checks
|
|
16
|
+
# POST /api/bridge {action: "time"} sets the bridge clock to now; {action: "reboot"} restarts it
|
|
17
|
+
# POST /api/preview {colors:, effects:} on the lights now; {stop: true} hands back to the calendar;
|
|
18
|
+
# {ping: true} keeps it up. With no ping for PREVIEW_GRACE seconds the preview is cleared.
|
|
19
|
+
# ponytail: a thread per connection but one request at a time under a lock; a slow bridge call holds up the next request.
|
|
20
|
+
class Web
|
|
21
|
+
PAGE = File.join(__dir__, "web.html")
|
|
22
|
+
PREVIEW_GRACE = 20
|
|
23
|
+
IDLE = 10 # seconds a connection may sit before sending a request; browsers open spare ones
|
|
24
|
+
# A bad config or an unreachable bridge: the page shows the message.
|
|
25
|
+
FAILURES = [Error, IndexError, ArgumentError, TypeError, Date::Error, JSON::ParserError,
|
|
26
|
+
SystemCallError, Net::OpenTimeout, Net::ReadTimeout].freeze
|
|
27
|
+
|
|
28
|
+
def initialize(client, config_path, port: 4567)
|
|
29
|
+
@c, @path, @port = client, config_path, port
|
|
30
|
+
@state_path = Sync.state_path(config_path)
|
|
31
|
+
@lock = Mutex.new
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def start
|
|
35
|
+
server = TCPServer.new("127.0.0.1", @port)
|
|
36
|
+
puts "everlights web: http://localhost:#{@port} (editing #{@path}; ctrl-c to stop)"
|
|
37
|
+
loop do
|
|
38
|
+
ready = IO.select([server], nil, nil, 5) # wake up now and then to drop an abandoned preview
|
|
39
|
+
expire_preview
|
|
40
|
+
Thread.new(server.accept) { handle(_1) } if ready
|
|
41
|
+
end
|
|
42
|
+
rescue Interrupt
|
|
43
|
+
puts
|
|
44
|
+
ensure
|
|
45
|
+
server&.close
|
|
46
|
+
begin
|
|
47
|
+
@lock.synchronize { stop_preview }
|
|
48
|
+
rescue StandardError => e
|
|
49
|
+
warn "web: couldn't clear the preview: #{e.message}"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# A bridge error leaves the preview in place, to try again on the next wake-up.
|
|
54
|
+
def expire_preview(now = Time.now)
|
|
55
|
+
@lock.synchronize { stop_preview if @preview_until && now > @preview_until }
|
|
56
|
+
rescue StandardError => e
|
|
57
|
+
warn "web: couldn't clear the preview, will retry: #{e.message}"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def stop_preview
|
|
61
|
+
return unless @preview_until
|
|
62
|
+
@c.clear
|
|
63
|
+
@preview_until = nil
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def handle(conn)
|
|
67
|
+
return unless conn.wait_readable(IDLE)
|
|
68
|
+
verb, path = conn.gets&.split
|
|
69
|
+
return unless path
|
|
70
|
+
headers = {}
|
|
71
|
+
while (line = conn.gets) && line != "\r\n"
|
|
72
|
+
k, v = line.split(":", 2)
|
|
73
|
+
headers[k.downcase] = v.to_s.strip
|
|
74
|
+
end
|
|
75
|
+
body = conn.read(headers["content-length"].to_i)
|
|
76
|
+
code, type, out = @lock.synchronize { respond(verb, path, headers, body) }
|
|
77
|
+
conn.write "HTTP/1.1 #{code} X\r\nContent-Type: #{type}; charset=utf-8\r\nContent-Length: #{out.bytesize}\r\n" \
|
|
78
|
+
"Cache-Control: no-store\r\nConnection: close\r\n\r\n#{out}"
|
|
79
|
+
rescue SystemCallError, IOError
|
|
80
|
+
nil # the browser hung up
|
|
81
|
+
ensure
|
|
82
|
+
conn.close
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def respond(verb, path, headers, body)
|
|
86
|
+
route(verb, path, headers, body)
|
|
87
|
+
rescue *FAILURES => e
|
|
88
|
+
[422, "application/json", JSON.generate(error: e.message)]
|
|
89
|
+
rescue StandardError => e
|
|
90
|
+
warn "web: #{e.class}: #{e.message}\n #{Array(e.backtrace).first(3).join("\n ")}"
|
|
91
|
+
[500, "application/json", JSON.generate(error: "#{e.class}: #{e.message}")]
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def route(verb, path, headers, body)
|
|
95
|
+
# Another site open in the browser can reach localhost: refuse foreign Host headers (DNS rebinding),
|
|
96
|
+
# and require JSON on writes so cross-site forms can't post without a CORS preflight we never answer.
|
|
97
|
+
return [403, "text/plain", "forbidden"] unless headers["host"].to_s.match?(/\A(localhost|127\.0\.0\.1)(:\d+)?\z/)
|
|
98
|
+
write = verb != "GET"
|
|
99
|
+
return [415, "text/plain", "send JSON"] if write && !headers["content-type"].to_s.start_with?("application/json")
|
|
100
|
+
|
|
101
|
+
case [verb, path.split("?").first]
|
|
102
|
+
when %w[GET /] then [200, "text/html", File.read(PAGE)]
|
|
103
|
+
when %w[GET /api/state] then [200, "application/json", JSON.generate(state)]
|
|
104
|
+
when %w[PUT /api/config]
|
|
105
|
+
saved = save(JSON.parse(body), headers["if-match"])
|
|
106
|
+
[saved ? 200 : 412, "application/json", JSON.generate(state)]
|
|
107
|
+
when %w[POST /api/apply]
|
|
108
|
+
plan = Sync.new(@c, load, state_path: @state_path).plan
|
|
109
|
+
plan.apply!
|
|
110
|
+
[200, "application/json", JSON.generate(state.merge(applied: plan.actions.size))]
|
|
111
|
+
when %w[GET /api/bridge]
|
|
112
|
+
status = @c.status
|
|
113
|
+
[200, "application/json", JSON.generate(status: status, now: Everlights.stamp(Time.now),
|
|
114
|
+
checks: Everlights.health(status, via_cloud: @c.is_a?(Client) && @c.cloud?).map { |ok, name, text| {ok: ok, name: name, text: text} })]
|
|
115
|
+
when %w[POST /api/bridge]
|
|
116
|
+
case JSON.parse(body)["action"]
|
|
117
|
+
when "time" then @c.set_time(Time.now)
|
|
118
|
+
when "reboot" then @c.reboot
|
|
119
|
+
else raise Error, "unknown action"
|
|
120
|
+
end
|
|
121
|
+
[200, "application/json", JSON.generate(ok: true)]
|
|
122
|
+
when %w[POST /api/preview]
|
|
123
|
+
req = JSON.parse(body)
|
|
124
|
+
if req["stop"] then stop_preview
|
|
125
|
+
elsif req["ping"] then @preview_until &&= Time.now + PREVIEW_GRACE
|
|
126
|
+
else
|
|
127
|
+
colors = Everlights.colors(req["colors"])
|
|
128
|
+
raise Error, "nothing to preview: no colors" if colors.empty?
|
|
129
|
+
@c.set(*colors, effects: Everlights.effects(req["effects"]))
|
|
130
|
+
@preview_until = Time.now + PREVIEW_GRACE
|
|
131
|
+
end
|
|
132
|
+
[200, "application/json", JSON.generate(previewing: !!@preview_until)]
|
|
133
|
+
else [404, "text/plain", "not found"]
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def load
|
|
138
|
+
config = Sync.load_config(@path)
|
|
139
|
+
ENV["TZ"] = config["timezone"] if config["timezone"]
|
|
140
|
+
# an unquoted 18:30 loads as a number; show and save it as "18:30"
|
|
141
|
+
hm = ->(v) { v.is_a?(Integer) ? format("%02d:%02d", *(v / Sync::YAML_MINUTE).divmod(60)) : v }
|
|
142
|
+
[config["defaults"], *config["schedule"]].each do |r|
|
|
143
|
+
%w[start end].each { r[_1] = hm.(r[_1]) if r.is_a?(Hash) && r.key?(_1) }
|
|
144
|
+
end
|
|
145
|
+
# a gradient ("FF0000..0000FF:5") reaches the page as the colors it makes, and is saved as them
|
|
146
|
+
(config["sequences"].is_a?(Hash) ? config["sequences"] : {}).each_value do |s|
|
|
147
|
+
s["colors"] = Everlights.colors(s["colors"]) if s.is_a?(Hash) && Array(s["colors"]).any? { _1.to_s.include?("..") }
|
|
148
|
+
rescue Error
|
|
149
|
+
nil # a bad one is left for the plan to report
|
|
150
|
+
end
|
|
151
|
+
config
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def version = Digest::SHA256.file(@path).hexdigest
|
|
155
|
+
|
|
156
|
+
# False, writing nothing, when the file isn't at `version` any more (edited by hand); no version skips the check.
|
|
157
|
+
def save(config, version = nil)
|
|
158
|
+
raise Error, "config must be an object" unless config.is_a?(Hash)
|
|
159
|
+
text = File.read(@path)
|
|
160
|
+
return false if version && version != Digest::SHA256.hexdigest(text)
|
|
161
|
+
# ponytail: one backup, never replaced: the file as it was before the page first saved it.
|
|
162
|
+
# Comments added by hand after that are lost on the next save; dated backups if that bites.
|
|
163
|
+
bak = "#{@path}.bak"
|
|
164
|
+
FileUtils.cp(@path, bak) unless File.exist?(bak)
|
|
165
|
+
header = text[/\A(?:#.*\n|[ \t]*\n)*/]
|
|
166
|
+
File.write(@path, header + Web.dump(config))
|
|
167
|
+
true
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# YAML like a person writes it: lists of plain values and small maps on one line.
|
|
171
|
+
def self.dump(config)
|
|
172
|
+
doc = YAML.parse_stream(YAML.dump(config))
|
|
173
|
+
doc.each do |n|
|
|
174
|
+
next unless n.respond_to?(:children) && n.children&.all?(Psych::Nodes::Scalar)
|
|
175
|
+
next unless n.is_a?(Psych::Nodes::Sequence) || (n.is_a?(Psych::Nodes::Mapping) && n.children.size <= 4)
|
|
176
|
+
n.style = n.class::FLOW
|
|
177
|
+
# "Name:30" can't be plain inside [...]; let libyaml quote it rather than tag it `! 'Name:30'`
|
|
178
|
+
n.children.each { _1.quoted = true if _1.plain }
|
|
179
|
+
end
|
|
180
|
+
doc.to_yaml.delete_prefix("---\n")
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def state
|
|
184
|
+
config = load
|
|
185
|
+
out = {config: config, version: version, effects: EFFECTS, today: Date.today.iso8601,
|
|
186
|
+
horizon: Integer(config["horizon_days"] || 120, exception: false) || 120, host: (@c.to_s if @c.is_a?(Client))}
|
|
187
|
+
sync = Sync.new(@c, config, state_path: @state_path)
|
|
188
|
+
plan = begin
|
|
189
|
+
sync.plan
|
|
190
|
+
rescue *FAILURES => e
|
|
191
|
+
out[:error] = e.message
|
|
192
|
+
nil
|
|
193
|
+
end
|
|
194
|
+
if (bridge = sync.bridge_seqs) # read by the plan, even one that found config problems
|
|
195
|
+
mine = (config["sequences"] || {}).keys.map(&:downcase)
|
|
196
|
+
out[:bridge_sequences] = bridge.reject { mine.include?(_1["alias"].downcase) }.sort_by { _1["alias"].downcase }
|
|
197
|
+
.map { {name: _1["alias"], colors: _1["pattern"], effects: _1["effects"], builtin: _1["id"].start_with?(BUILTIN_PREFIX)} }
|
|
198
|
+
end
|
|
199
|
+
return out unless plan
|
|
200
|
+
|
|
201
|
+
nights = {}
|
|
202
|
+
plan.shows.each do |rule, list|
|
|
203
|
+
list.each { |s, e| nights[s.to_date.iso8601] = {rule: rule, start: s.strftime("%H:%M"), end: e.strftime("%H:%M")} }
|
|
204
|
+
end
|
|
205
|
+
plan.skips.each do |d, rule, why|
|
|
206
|
+
next if why.end_with?(" wins this night")
|
|
207
|
+
nights[d.iso8601] ||= {rule: rule, note: why} # tonight's show, once under way, is in shows and stays
|
|
208
|
+
end
|
|
209
|
+
out.merge(nights: nights, plan: plan.actions.map { {kind: _1.kind, op: _1.op, name: _1.name, detail: _1.detail} })
|
|
210
|
+
rescue *FAILURES => e
|
|
211
|
+
(out || {config: config}).merge(error: e.message)
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
end
|
data/lib/everlights.rb
CHANGED
|
@@ -20,16 +20,33 @@ module Everlights
|
|
|
20
20
|
BUILTIN_PREFIX = "00000000-0000-0000-0000-" # ids of EverLights' stock sequences
|
|
21
21
|
DEFAULT_SECONDS = 20
|
|
22
22
|
EFFECTS = %w[bars blink chase fade gradient lightning melt pingPong random reverseChase strobe twinkle wipe].freeze
|
|
23
|
+
# Firmware B5010 (Oct 2026) answers every endpoint but GET /v1 with 410 {"error":"gone","cloud":true}.
|
|
24
|
+
NO_LOCAL_CONTROL = "the bridge's firmware has turned off local control (410 gone): firmware B5010 and later " \
|
|
25
|
+
"only take commands from the EverLights cloud. Run `everlights login` to send them that way."
|
|
23
26
|
|
|
24
27
|
class Client
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
WRITE_GAP = 0.25 # seconds between writes through the cloud; the bridge misbehaves when they stack up
|
|
29
|
+
|
|
30
|
+
# host: the bridge on the LAN. cloud: an Everlights::Cloud, for firmware B5010+ (no local control).
|
|
31
|
+
def initialize(host = nil, timeout: 10, cloud: nil)
|
|
32
|
+
if (@cloud = cloud)
|
|
33
|
+
raise Error, "not logged in; run `everlights login`" unless cloud.bridge
|
|
34
|
+
uri = URI(cloud.tunnel)
|
|
35
|
+
@prefix = "#{uri.path}/#{cloud.bridge}/proxy"
|
|
36
|
+
timeout = Cloud::TIMEOUT
|
|
37
|
+
else
|
|
38
|
+
host ||= ENV["EVERLIGHTS_HOST"]
|
|
39
|
+
raise Error, "no bridge: run `everlights login`, or pass --host or set EVERLIGHTS_HOST for a local one" unless host
|
|
40
|
+
uri = URI("http://#{host}")
|
|
41
|
+
end
|
|
29
42
|
@http = Net::HTTP.new(uri.host, uri.port)
|
|
43
|
+
@http.use_ssl = uri.scheme == "https"
|
|
30
44
|
@http.open_timeout = @http.read_timeout = timeout
|
|
31
45
|
end
|
|
32
46
|
|
|
47
|
+
def cloud? = !!@cloud
|
|
48
|
+
def to_s = @cloud ? "bridge #{@cloud.bridge} via the EverLights cloud" : "bridge #{@http.address}"
|
|
49
|
+
|
|
33
50
|
def sequences = Sequences.new(self)
|
|
34
51
|
def calendar = Calendar.new(self)
|
|
35
52
|
|
|
@@ -131,27 +148,56 @@ module Everlights
|
|
|
131
148
|
def get(path) = request(Net::HTTP::Get, path)
|
|
132
149
|
|
|
133
150
|
def request(verb, path, body = nil)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
151
|
+
pace if @cloud && (verb != Net::HTTP::Get || path.end_with?("/reboot"))
|
|
152
|
+
res = send_request(verb, path, body)
|
|
153
|
+
# the tunnel turned the token away before the bridge saw the request, so once more is safe
|
|
154
|
+
res = send_request(verb, path, body, fresh: true) if @cloud && res.code == "401"
|
|
155
|
+
raise Error, NO_LOCAL_CONTROL if res.code == "410" && res.body.to_s.match?(/"cloud"\s*:\s*true/)
|
|
137
156
|
raise Error, "#{verb::METHOD} #{path} -> #{res.code}: #{res.body}" unless res.is_a?(Net::HTTPSuccess)
|
|
138
157
|
res.body.to_s.empty? ? nil : JSON.parse(res.body)
|
|
139
158
|
end
|
|
140
159
|
|
|
160
|
+
def send_request(verb, path, body, fresh: false)
|
|
161
|
+
req = verb.new(@cloud ? "#{@prefix}#{path}#{"/" if path == "/v1"}" : path, "Content-Type" => "application/json")
|
|
162
|
+
req["Authorization"] = "Bearer #{@cloud.tunnel_token(fresh: fresh)}" if @cloud
|
|
163
|
+
req.body = JSON.generate(body) if body
|
|
164
|
+
@http.request(req)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def pace
|
|
168
|
+
wait = WRITE_GAP - (Process.clock_gettime(Process::CLOCK_MONOTONIC) - (@last_write || 0))
|
|
169
|
+
sleep wait if wait.positive?
|
|
170
|
+
@last_write = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
171
|
+
end
|
|
172
|
+
|
|
141
173
|
def colors(pattern) = Everlights.colors(pattern)
|
|
142
174
|
def effects_body(effects) = Everlights.effects(effects)
|
|
143
175
|
def stamp(t) = Everlights.stamp(t)
|
|
144
176
|
end
|
|
145
177
|
|
|
146
|
-
# ["#ff0000", ...] -> ["FF0000", ...]
|
|
178
|
+
# ["#ff0000", ...] -> ["FF0000", ...]; a gradient "FF0000..0000FF:5" becomes its 5 colors
|
|
147
179
|
def self.colors(pattern)
|
|
148
|
-
Array(pattern).
|
|
149
|
-
hex = c.to_s.
|
|
180
|
+
Array(pattern).flat_map do |c|
|
|
181
|
+
hex = c.to_s.delete("#").upcase
|
|
182
|
+
next gradient(hex) if hex.include?("..")
|
|
150
183
|
raise Error, "bad color #{c.inspect}, want RRGGBB" unless hex.match?(/\A\h{6}\z/)
|
|
151
184
|
hex
|
|
152
185
|
end
|
|
153
186
|
end
|
|
154
187
|
|
|
188
|
+
# "FF7A1E..FF9E3D:4" -> 4 colors evenly from the first to the last; middle stops bend it: "FF0000..FFFFFF..0000FF:9"
|
|
189
|
+
def self.gradient(text)
|
|
190
|
+
m = text.match(/\A(\h{6}(?:\.\.\h{6})+):(\d+)\z/) or raise Error, "bad gradient #{text.inspect}, want RRGGBB..RRGGBB:COUNT"
|
|
191
|
+
stops = m[1].split("..").map { |h| h.scan(/../).map { _1.to_i(16) } }
|
|
192
|
+
count = m[2].to_i
|
|
193
|
+
raise Error, "gradient #{text.inspect}: count must be at least 2" if count < 2
|
|
194
|
+
(0...count).map do |i|
|
|
195
|
+
at = i * (stops.size - 1) / (count - 1).to_f # position along the stops, 0..stops-1
|
|
196
|
+
k = [at.floor, stops.size - 2].min
|
|
197
|
+
stops[k].zip(stops[k + 1]).map { |a, b| format("%02X", (a + (b - a) * (at - k)).round) }.join
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
155
201
|
# {chase: 100} or the API's [{"effectType" => "chase", "value" => 100}] -> API form with string keys
|
|
156
202
|
def self.effects(effects)
|
|
157
203
|
(effects || {}).map do |e|
|
|
@@ -161,6 +207,30 @@ module Everlights
|
|
|
161
207
|
end
|
|
162
208
|
end
|
|
163
209
|
|
|
210
|
+
# [[ok, name, text], ...] from Client#status; ok is true, false, or :info.
|
|
211
|
+
# ponytail: thresholds are guesses from one bridge; tune when real failures show what matters
|
|
212
|
+
# via_cloud: commands go through the cloud, so the bridge's local control being off is expected.
|
|
213
|
+
# Firmware B5010 stopped reporting network and memory; those show as info, not warnings.
|
|
214
|
+
def self.health(b, now: Time.now, via_cloud: false)
|
|
215
|
+
ago = ->(v) { v ? ((now - Time.parse(v)) / 60).round : Float::INFINITY }
|
|
216
|
+
mins = ->(m) { m.infinite? ? "never" : "#{m} min ago" }
|
|
217
|
+
cloud, radio = ago.(b["lastServerCheckin"]), ago.(b["lastRadioResponse"])
|
|
218
|
+
unreported = ->(name) { [:info, name, "not reported by firmware #{b["firmwareVersion"]}"] }
|
|
219
|
+
[
|
|
220
|
+
*([[via_cloud ? :info : false, "local control",
|
|
221
|
+
"off in firmware #{b["firmwareVersion"]}; #{via_cloud ? "commands go through the cloud" : "run `everlights login`"}"]] if b["cloud"]),
|
|
222
|
+
[!!b["serverReachable"] && cloud <= 15, "cloud", "#{b["serverReachable"] ? "reachable" : "unreachable"}, checked in #{mins.(cloud)}"],
|
|
223
|
+
b.key?("network") ? [!!b.dig("network", "ntp"), "clock", "ntp #{b.dig("network", "ntp") ? "on" : "off"}"] : unreported.("clock"),
|
|
224
|
+
b.key?("minFreeHeap") ? [b["minFreeHeap"].to_i >= 10_000, "memory", "lowest free since boot #{b["minFreeHeap"]} bytes (warn under 10000)"] : unreported.("memory"),
|
|
225
|
+
[radio <= 10, "radio", "answered #{mins.(radio)}#{", #{b["radioRebootCount"]} radio reboots" if b["radioRebootCount"]}"],
|
|
226
|
+
*b["zones"].map do |z|
|
|
227
|
+
last = ago.(z["lastResponseDate"])
|
|
228
|
+
[!!z["active"] && last <= 10, "zone #{z["serial"]}", "#{z["active"] ? "active" : "inactive"}, answered #{mins.(last)}, #{z["rebootCount"]} reboots"]
|
|
229
|
+
end,
|
|
230
|
+
[:info, "reboots", "#{b["rebootCount"]} total#{", last reset reason #{b["resetReason"]}" if b["resetReason"]}"]
|
|
231
|
+
]
|
|
232
|
+
end
|
|
233
|
+
|
|
164
234
|
def self.stamp(t) = (t.is_a?(Time) ? t : Time.parse(t.to_s)).getutc.iso8601(6)
|
|
165
235
|
|
|
166
236
|
class Sequences
|
|
@@ -254,3 +324,4 @@ module Everlights
|
|
|
254
324
|
end
|
|
255
325
|
|
|
256
326
|
require_relative "everlights/sync"
|
|
327
|
+
require_relative "everlights/cloud"
|
data/skills/everlights/SKILL.md
CHANGED
|
@@ -5,18 +5,20 @@ description: Control EverLights permanent outdoor lights through the local bridg
|
|
|
5
5
|
|
|
6
6
|
# EverLights
|
|
7
7
|
|
|
8
|
-
The `everlights` CLI talks to the bridge
|
|
8
|
+
The `everlights` CLI talks to the bridge through the EverLights cloud once the user has run `everlights login` (firmware B5010 and later need this). On older firmware it can use the LAN instead with `EVERLIGHTS_HOST` (the bridge's IP) or `--host`. Lists print text (add `--json` for JSON); `status`, `zones` and `show` print JSON.
|
|
9
9
|
|
|
10
10
|
## Before you write anything
|
|
11
11
|
|
|
12
12
|
1. Run `everlights calendar list` and `everlights show` (names what's playing and which show it's from) first (`everlights bridge health` if something seems broken; it marks problems WARN). Report what's already scheduled or showing.
|
|
13
13
|
2. Confirm before every write: `set`, `play`, `off`, `clear`, `sequence add/update/remove`, `calendar add/remove` and `bridge time`. These change real lights on a real house, so state the exact command you'll run.
|
|
14
|
-
3.
|
|
14
|
+
3. If a command fails with "turned off local control" or "not logged in", the bridge is on firmware B5010 or later and needs `everlights login EMAIL`. Ask the user to run it themselves. Never ask for their password or handle it yourself.
|
|
15
|
+
4. Only run `bridge reboot --yes` when the user explicitly asks; it interrupts the lights. The CLI refuses to remove built-in sequences, or sequences an event still uses.
|
|
15
16
|
|
|
16
17
|
## Concepts
|
|
17
18
|
|
|
18
19
|
- **Zone**: one run of pixels, identified by serial. `everlights zones` lists them. Commands default to all zones; `--zone SERIAL` narrows one.
|
|
19
20
|
- **Sequence**: a saved pattern of hex colors (`RRGGBB`, repeated along the run) plus up to a few effects. The bridge has about 96 built-ins (`everlights sequence list xmas` searches by name; `*` marks user-made ones). Sequences added here show up in the EverLights app under Personal. Built-in names include "Birthday", so give personal sequences distinct names (e.g. "My Birthday").
|
|
21
|
+
- **Gradient**: anywhere a color goes, `FF0000..0000FF:5` is 5 colors blended evenly; middle stops bend it (`FF0000..FFFFFF..0000FF:9`).
|
|
20
22
|
- **Effect**: `--effect TYPE=N`, N 0-255 (default 128; higher seems faster). Types: bars blink chase fade gradient lightning melt pingPong random reverseChase strobe twinkle wipe. Built-ins often stack two, e.g. `fade` + `reverseChase`.
|
|
21
23
|
- **Manual program** (`set`/`play`): shows immediately. During a scheduled show, it only lasts until the show's next sequence change (about 20 seconds). Outside a show it stays. `clear` hands control back to the calendar.
|
|
22
24
|
- **Calendar entry**: a scheduled show. It cycles its sequences (`NAME:SECONDS`, default 20) during each night's window. The bridge stores it, so it runs with no computer on. Default window: dusk to 23:00.
|
|
@@ -56,12 +58,14 @@ el.calendar.remove "2026-12-24", "Christmas"
|
|
|
56
58
|
|
|
57
59
|
## Sync (planning shows months ahead)
|
|
58
60
|
|
|
59
|
-
When the user wants a recurring or seasonal plan ("Christmas every December", "Fridays in football season"), edit `config/everlights.yml` rather than adding calendar entries one by one. The format reference is `config/everlights.example.yml`.
|
|
61
|
+
When the user wants a recurring or seasonal plan ("Christmas every December", "Fridays in football season"), edit `config/everlights.yml` rather than adding calendar entries one by one. If there's no config yet, `everlights init` writes a starter one. The format reference is `config/everlights.example.yml`.
|
|
60
62
|
|
|
61
|
-
1. Edit `sequences:` or `schedule:`. Rules higher in the list win nights they share.
|
|
63
|
+
1. Edit `sequences:` or `schedule:`. Rules higher in the list win nights they share. For a team's games or other events in a calendar, a rule can use `ics: <feed URL>` with `match: <title text>`.
|
|
62
64
|
2. Run `everlights sync --dry-run` and show the user the plan, including the Skipped and No show sections. `everlights sync --check` is the same plan, but exits 2 when anything would change.
|
|
63
65
|
3. Run `everlights sync` only after they confirm.
|
|
64
66
|
|
|
67
|
+
If the user would rather click and drag, suggest `everlights web`: it edits the same file and has its own Apply button.
|
|
68
|
+
|
|
65
69
|
Sync only changes what it created itself. Config problems abort before anything is written; fix every one it lists. Use `--adopt` only when the user says the state file was lost.
|
|
66
70
|
|
|
67
71
|
## Unverified
|
|
@@ -70,4 +74,3 @@ Sync only changes what it created itself. Config problems abort before anything
|
|
|
70
74
|
- Whether "dusk" shows really start at dusk. The bridge stores a 17:00 placeholder, so they may start at 17:00. Use `--start` when the exact time matters.
|
|
71
75
|
- What N means for each effect.
|
|
72
76
|
- Whether a calendar entry overlapping another replaces it or conflicts. Check `calendar list` afterwards.
|
|
73
|
-
- `calendar remove` on a night that isn't an entry's last edits the event with a PUT. The API spec has it; not yet tried on the bridge.
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: everlights
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ricky Chilcott
|
|
@@ -9,9 +9,10 @@ bindir: exe
|
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
|
-
description: 'Control EverLights permanent lights
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
description: 'Control EverLights permanent lights: show colors, manage sequences,
|
|
13
|
+
and schedule a year of shows ahead on the bridge''s calendar from one config file,
|
|
14
|
+
with holidays, calendar feeds and gradients. Reaches firmware B5010+ bridges through
|
|
15
|
+
the EverLights cloud, older ones on the LAN. Unofficial; stdlib only.'
|
|
15
16
|
email: ricky@rickychilcott.com
|
|
16
17
|
executables:
|
|
17
18
|
- everlights
|
|
@@ -20,9 +21,13 @@ extra_rdoc_files: []
|
|
|
20
21
|
files:
|
|
21
22
|
- LICENSE
|
|
22
23
|
- README.md
|
|
24
|
+
- config/everlights.example.yml
|
|
23
25
|
- exe/everlights
|
|
24
26
|
- lib/everlights.rb
|
|
27
|
+
- lib/everlights/cloud.rb
|
|
25
28
|
- lib/everlights/sync.rb
|
|
29
|
+
- lib/everlights/web.html
|
|
30
|
+
- lib/everlights/web.rb
|
|
26
31
|
- skills/everlights/SKILL.md
|
|
27
32
|
homepage: https://github.com/rickychilcott/everlights
|
|
28
33
|
licenses:
|
|
@@ -48,5 +53,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
48
53
|
requirements: []
|
|
49
54
|
rubygems_version: 4.0.20
|
|
50
55
|
specification_version: 4
|
|
51
|
-
summary: Client and CLI for the EverLights Smart Lights Bridge
|
|
56
|
+
summary: Client and CLI for the EverLights v3 Smart Lights Bridge, through the cloud
|
|
57
|
+
or the local API
|
|
52
58
|
test_files: []
|