esphome 0.2.0 → 0.3.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/exe/esphome-monitor +3 -152
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f93b29cfdfc4ad5759deb07b724b95a126dc957868761ff632468dc60fa411b8
|
4
|
+
data.tar.gz: 4a86702fe2ddd63049607882f92be4274fc16bedd808431ae083483143435bc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27009b78580310aa7e285dc1fce69db2c9167a3db7f0f69267ed069d308e7f816189625f040bc3f265c6d2d112fec2c3509f56c0d8db8cc06a90f9d868db038f
|
7
|
+
data.tar.gz: 635d6166274d1937632f9ce90514fb0eb1eee8fa8a5c4aa4277e7f889bb6a329d4feb9853ad9857c350b28cde831f3c25b0270622daa96da2a28ef11fedb640d
|
data/exe/esphome-monitor
CHANGED
@@ -1,66 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require "
|
5
|
-
require "esphome"
|
6
|
-
require "time"
|
7
|
-
|
8
|
-
ANSI_COLOR_MAP = {
|
9
|
-
30 => Curses::COLOR_BLACK,
|
10
|
-
31 => Curses::COLOR_RED,
|
11
|
-
32 => Curses::COLOR_GREEN,
|
12
|
-
33 => Curses::COLOR_YELLOW,
|
13
|
-
34 => Curses::COLOR_BLUE,
|
14
|
-
35 => Curses::COLOR_MAGENTA,
|
15
|
-
36 => Curses::COLOR_CYAN,
|
16
|
-
37 => Curses::COLOR_WHITE
|
17
|
-
}.freeze
|
18
|
-
|
19
|
-
# Regex to match ANSI color codes (like \e[31m)
|
20
|
-
ANSI_ESCAPE_REGEX = /\e\[(\d+(?:;\d+)*)m/
|
21
|
-
|
22
|
-
def parse_sgr_codes(codes)
|
23
|
-
color = nil
|
24
|
-
attr = Curses::A_NORMAL
|
25
|
-
|
26
|
-
codes.each do |code|
|
27
|
-
code = code.to_i
|
28
|
-
if ANSI_COLOR_MAP.key?(code)
|
29
|
-
color = ANSI_COLOR_MAP[code]
|
30
|
-
elsif code == 1
|
31
|
-
attr |= Curses::A_BOLD
|
32
|
-
elsif code == 4
|
33
|
-
attr |= Curses::A_UNDERLINE
|
34
|
-
elsif code.zero?
|
35
|
-
attr = Curses::A_NORMAL
|
36
|
-
color = nil
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
[color, attr]
|
41
|
-
end
|
42
|
-
|
43
|
-
def parse_ansi_and_render(line)
|
44
|
-
@win.clrtoeol
|
45
|
-
current_color = nil
|
46
|
-
current_attr = Curses::A_NORMAL
|
47
|
-
|
48
|
-
line.split(ANSI_ESCAPE_REGEX).each_with_index do |part, i|
|
49
|
-
if i.odd?
|
50
|
-
codes = part.split(";").map(&:to_i)
|
51
|
-
current_color, current_attr = parse_sgr_codes(codes)
|
52
|
-
elsif current_color
|
53
|
-
pair_id = current_color + 1
|
54
|
-
@win.attron(Curses.color_pair(pair_id) | current_attr) do
|
55
|
-
@win.addstr(part)
|
56
|
-
end
|
57
|
-
else
|
58
|
-
@win.attron(current_attr) do
|
59
|
-
@win.addstr(part)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
4
|
+
require "esphome/cli/monitor"
|
64
5
|
|
65
6
|
if ARGV.size == 1
|
66
7
|
uri = "http://localhost:6052/"
|
@@ -95,96 +36,6 @@ if uri
|
|
95
36
|
end
|
96
37
|
end
|
97
38
|
|
98
|
-
|
99
|
-
|
100
|
-
def print_entity(entity, clear_line: true)
|
101
|
-
return unless @entities.key?(entity.key) # has an unsupported entity
|
102
|
-
|
103
|
-
@win.setpos(@entities[entity.key] + 3, 0)
|
104
|
-
@win.clrtoeol if clear_line
|
105
|
-
name = "#{entity.class.name.split("::").last} - #{entity.name}"
|
106
|
-
@win.addstr("#{name.ljust(40)}: [#{Time.now.strftime("%H:%M:%S")}] #{entity.formatted_state}")
|
107
|
-
end
|
108
|
-
|
109
|
-
def visible_lines
|
110
|
-
@win.maxy - @entities.size - 5
|
111
|
-
end
|
112
|
-
|
113
|
-
def render_log(visible_lines = nil)
|
114
|
-
visible_lines ||= self.visible_lines
|
115
|
-
|
116
|
-
@log_lines.each_with_index do |log_line, idx|
|
117
|
-
break if idx >= visible_lines
|
118
|
-
|
119
|
-
@win.setpos(@entities.size + 4 + idx, 0)
|
120
|
-
|
121
|
-
parse_ansi_and_render(log_line)
|
122
|
-
end
|
123
|
-
end
|
39
|
+
device = ESPHome::Device.new(address, encryption_key, logger: Logger.new(IO::NULL))
|
124
40
|
|
125
|
-
|
126
|
-
@win.clear
|
127
|
-
@win.setpos(0, 0)
|
128
|
-
@win.addstr("ESPHome")
|
129
|
-
@win.setpos(1, 0)
|
130
|
-
@win.addstr("#{@device.friendly_name.ljust(45)} (#{@device.esphome_version} - #{@device.compilation_time})")
|
131
|
-
@win.setpos(2, 0)
|
132
|
-
@win.addstr("=" * 80)
|
133
|
-
|
134
|
-
@device.entities.each_value do |entity|
|
135
|
-
next unless entity.is_a?(ESPHome::Entity::HasState)
|
136
|
-
|
137
|
-
print_entity(entity, clear_line: false)
|
138
|
-
end
|
139
|
-
|
140
|
-
render_log
|
141
|
-
|
142
|
-
@win.refresh
|
143
|
-
end
|
144
|
-
|
145
|
-
Signal.trap("SIGWINCH") do
|
146
|
-
render_all
|
147
|
-
end
|
148
|
-
|
149
|
-
@log_lines = []
|
150
|
-
|
151
|
-
@device.on_message do |entity_or_log_line|
|
152
|
-
if entity_or_log_line.is_a?(String)
|
153
|
-
visible_lines = self.visible_lines
|
154
|
-
@log_lines << "[#{Time.now.strftime("%H:%M:%S")}]#{entity_or_log_line}"
|
155
|
-
@log_lines.shift if @log_lines.size > [20, visible_lines].max
|
156
|
-
|
157
|
-
render_log
|
158
|
-
else
|
159
|
-
print_entity(entity_or_log_line)
|
160
|
-
end
|
161
|
-
@win.refresh
|
162
|
-
end
|
163
|
-
|
164
|
-
@device.connect
|
165
|
-
|
166
|
-
@entities = {}
|
167
|
-
@device.entities.values.grep(ESPHome::Entity::HasState).sort_by(&:name).each_with_index do |entity, idx|
|
168
|
-
@entities[entity.key] = idx
|
169
|
-
end
|
170
|
-
|
171
|
-
Curses.init_screen
|
172
|
-
begin
|
173
|
-
Curses.noecho
|
174
|
-
Curses.start_color
|
175
|
-
Curses.use_default_colors
|
176
|
-
@win = Curses.stdscr
|
177
|
-
ANSI_COLOR_MAP.each_value do |color|
|
178
|
-
Curses.init_pair(color + 1, color, -1)
|
179
|
-
end
|
180
|
-
|
181
|
-
render_all
|
182
|
-
|
183
|
-
@device.stream_states
|
184
|
-
@device.stream_log(dump_config: true)
|
185
|
-
@device.loop
|
186
|
-
rescue Interrupt
|
187
|
-
# exitting
|
188
|
-
ensure
|
189
|
-
Curses.close_screen
|
190
|
-
end
|
41
|
+
ESPHome::Cli::Monitor.run(device)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: esphome
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cody Cutrer
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-07-
|
10
|
+
date: 2025-07-05 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: curses
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
|
-
rubygems_version: 3.6.
|
110
|
+
rubygems_version: 3.6.3
|
111
111
|
specification_version: 4
|
112
112
|
summary: ESPHome Library and CLI for Ruby
|
113
113
|
test_files: []
|