balboa_worldwide_app 1.2.5 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/bwa/proxy.rb CHANGED
@@ -1,31 +1,31 @@
1
- require 'socket'
2
- require 'bwa/message'
1
+ # frozen_string_literal: true
2
+
3
+ require "socket"
4
+ require "bwa/logger"
5
+ require "bwa/message"
3
6
 
4
7
  module BWA
5
8
  class Proxy
6
- def initialize(host, port: 4257, listen_port: 4257)
9
+ def initialize(host, port: 4257)
7
10
  @host, @port = host, port
8
11
  @listen_socket = TCPServer.open(port)
9
12
  end
10
13
 
11
14
  def run
12
- loop do
13
- client_socket = @listen_socket.accept
14
- server_socket = TCPSocket.new(@host, @port)
15
- t1 = Thread.new do
16
- shuffle_messages(client_socket, server_socket, "Client")
17
- end
18
- t2 = Thread.new do
19
- shuffle_messages(server_socket, client_socket, "Server")
20
- end
21
- t1.join
22
- t2.join
23
- break
15
+ client_socket = @listen_socket.accept
16
+ server_socket = TCPSocket.new(@host, @port)
17
+ t1 = Thread.new do
18
+ shuffle_messages(client_socket, server_socket, "Client")
19
+ end
20
+ t2 = Thread.new do
21
+ shuffle_messages(server_socket, client_socket, "Server")
24
22
  end
23
+ t1.join
24
+ t2.join
25
25
  end
26
26
 
27
27
  def shuffle_messages(socket1, socket2, tag)
28
- leftover_data = "".force_encoding(Encoding::ASCII_8BIT)
28
+ leftover_data = (+"").force_encoding(Encoding::ASCII_8BIT)
29
29
  loop do
30
30
  if leftover_data.length < 2 || leftover_data.length < leftover_data[1].ord + 2
31
31
  begin
@@ -41,12 +41,12 @@ module BWA
41
41
  end
42
42
  data_length = leftover_data[1].ord
43
43
  data = leftover_data[0...(data_length + 2)]
44
- leftover_data = leftover_data[(data_length + 2)..-1] || ''
44
+ leftover_data = leftover_data[(data_length + 2)..-1] || ""
45
45
  begin
46
46
  message = Message.parse(data)
47
- puts "#{tag}: #{message.inspect}"
47
+ BWA.logger.info "#{tag}: #{message.inspect}"
48
48
  rescue InvalidMessage => e
49
- puts "#{tag}: #{e}"
49
+ BWA.logger.info "#{tag}: #{e}"
50
50
  end
51
51
  socket2.send(data, 0)
52
52
  end
data/lib/bwa/server.rb CHANGED
@@ -1,5 +1,8 @@
1
- require 'socket'
2
- require 'bwa/message'
1
+ # frozen_string_literal: true
2
+
3
+ require "socket"
4
+ require "bwa/logger"
5
+ require "bwa/message"
3
6
 
4
7
  module BWA
5
8
  class Server
@@ -11,42 +14,40 @@ module BWA
11
14
  def run
12
15
  loop do
13
16
  socket = @listen_socket.accept
14
- #Thread.new do
15
- run_client(socket)
16
- #end
17
- break
17
+ run_client(socket)
18
18
  end
19
19
  end
20
20
 
21
21
  def send_message(socket, message)
22
22
  length = message.length + 2
23
- full_message = "#{length.chr}#{message}".force_encoding(Encoding::ASCII_8BIT)
23
+ full_message = (+"#{length.chr}#{message}").force_encoding(Encoding::ASCII_8BIT)
24
24
  checksum = CRC.checksum(full_message)
25
- socket.send("\x7e#{full_message}#{checksum.chr}\x7e".force_encoding(Encoding::ASCII_8BIT), 0)
25
+ socket.send((+"\x7e#{full_message}#{checksum.chr}\x7e").force_encoding(Encoding::ASCII_8BIT), 0)
26
26
  end
27
27
 
28
28
  def run_client(socket)
29
- puts "Received connection from #{socket.remote_address.inspect}"
29
+ BWA.logger.info "Received connection from #{socket.remote_address.inspect}"
30
30
 
31
31
  send_status(socket)
32
32
  loop do
33
- if IO.select([socket], nil, nil, 1)
33
+ if socket.wait_readable(1)
34
34
  data = socket.recv(128)
35
35
  break if data.empty?
36
+
36
37
  begin
37
38
  message = Message.parse(data)
38
- puts message.raw_data.unpack("H*").first.scan(/[0-9a-f]{2}/).join(' ')
39
- puts message.inspect
39
+ BWA.logger.info BWA.raw2str(message.raw_data)
40
+ BWA.logger.info message.inspect
40
41
 
41
42
  case message
42
43
  when Messages::ConfigurationRequest
43
44
  send_configuration(socket)
44
45
  when Messages::ControlConfigurationRequest
45
46
  message.type == 1 ? send_control_configuration(socket) : send_control_configuration2(socket)
46
- when Messages::SetTemperature
47
+ when Messages::SetTargetTemperature
47
48
  temperature = message.temperature
48
49
  temperature /= 2.0 if @status.temperature_scale == :celsius
49
- @status.set_temperature = temperature
50
+ @status.target_temperature = temperature
50
51
  when Messages::SetTemperatureScale
51
52
  @status.temperature_scale = message.scale
52
53
  when Messages::ToggleItem
@@ -64,8 +65,8 @@ module BWA
64
65
  end
65
66
  end
66
67
  rescue BWA::InvalidMessage => e
67
- puts e.message
68
- puts e.raw_data.unpack("H*").first.scan(/[0-9a-f]{2}/).join(' ')
68
+ BWA.logger.warn e.message
69
+ BWA.logger.warn BWA.raw2str(e.raw_data)
69
70
  end
70
71
  else
71
72
  send_status(socket)
@@ -74,16 +75,18 @@ module BWA
74
75
  end
75
76
 
76
77
  def send_status(socket)
77
- puts "sending #{@status.inspect}"
78
+ BWA.logger.info "sending #{@status.inspect}"
78
79
  socket.send(@status.serialize, 0)
79
80
  end
80
81
 
81
82
  def send_configuration(socket)
82
- send_message(socket, "\x0a\xbf\x94\x02\x02\x80\x00\x15\x27\x10\xab\xd2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x27\xff\xff\x10\xab\xd2")
83
+ send_message(socket,
84
+ "\x0a\xbf\x94\x02\x02\x80\x00\x15\x27\x10\xab\xd2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x27\xff\xff\x10\xab\xd2") # rubocop:disable Layout/LineLength
83
85
  end
84
86
 
85
87
  def send_control_configuration(socket)
86
- send_message(socket, "\x0a\xbf\x24\x64\xdc\x11\x00\x42\x46\x42\x50\x32\x30\x20\x20\x01\x3d\x12\x38\x2e\x01\x0a\x04\x00")
88
+ send_message(socket,
89
+ "\x0a\xbf\x24\x64\xdc\x11\x00\x42\x46\x42\x50\x32\x30\x20\x20\x01\x3d\x12\x38\x2e\x01\x0a\x04\x00")
87
90
  end
88
91
 
89
92
  def send_control_configuration2(socket)
data/lib/bwa/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BWA
2
- VERSION = '1.2.5'
4
+ VERSION = "2.0.2"
3
5
  end
metadata CHANGED
@@ -1,71 +1,77 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: balboa_worldwide_app
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-27 00:00:00.000000000 Z
11
+ date: 2021-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: digest-crc
14
+ name: ccutrer-serialport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.4'
19
+ version: 1.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.4'
26
+ version: 1.0.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: mqtt
28
+ name: digest-crc
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.5.0
33
+ version: '0.4'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.5.0
40
+ version: '0.4'
41
41
  - !ruby/object:Gem::Dependency
42
- name: net-telnet-rfc2217
42
+ name: mqtt-homeassistant
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.0.3
47
+ version: '0.1'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 0.1.3
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
55
  - - "~>"
53
56
  - !ruby/object:Gem::Version
54
- version: 0.0.3
57
+ version: '0.1'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.1.3
55
61
  - !ruby/object:Gem::Dependency
56
- name: ccutrer-serialport
62
+ name: net-telnet-rfc2217
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: 1.0.0
67
+ version: 0.0.3
62
68
  type: :runtime
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: 1.0.0
74
+ version: 0.0.3
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: sd_notify
71
77
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +92,14 @@ dependencies:
86
92
  requirements:
87
93
  - - "~>"
88
94
  - !ruby/object:Gem::Version
89
- version: '9.0'
95
+ version: '11.0'
90
96
  type: :development
91
97
  prerelease: false
92
98
  version_requirements: !ruby/object:Gem::Requirement
93
99
  requirements:
94
100
  - - "~>"
95
101
  - !ruby/object:Gem::Version
96
- version: '9.0'
102
+ version: '11.0'
97
103
  - !ruby/object:Gem::Dependency
98
104
  name: rake
99
105
  requirement: !ruby/object:Gem::Requirement
@@ -108,21 +114,67 @@ dependencies:
108
114
  - - "~>"
109
115
  - !ruby/object:Gem::Version
110
116
  version: '13.0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rubocop
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '1.23'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '1.23'
131
+ - !ruby/object:Gem::Dependency
132
+ name: rubocop-performance
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '1.12'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '1.12'
145
+ - !ruby/object:Gem::Dependency
146
+ name: rubocop-rake
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '0.6'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '0.6'
111
159
  description:
112
160
  email: cody@cutrer.com'
113
161
  executables:
162
+ - bwa_client
163
+ - bwa_server
164
+ - bwa_proxy
114
165
  - bwa_mqtt_bridge
115
166
  extensions: []
116
167
  extra_rdoc_files: []
117
168
  files:
118
- - bin/bwa_client
119
- - bin/bwa_mqtt_bridge
120
- - bin/bwa_proxy
121
- - bin/bwa_server
169
+ - exe/bwa_client
170
+ - exe/bwa_mqtt_bridge
171
+ - exe/bwa_proxy
172
+ - exe/bwa_server
122
173
  - lib/balboa_worldwide_app.rb
123
174
  - lib/bwa/client.rb
124
175
  - lib/bwa/crc.rb
125
176
  - lib/bwa/discovery.rb
177
+ - lib/bwa/logger.rb
126
178
  - lib/bwa/message.rb
127
179
  - lib/bwa/messages/configuration.rb
128
180
  - lib/bwa/messages/configuration_request.rb
@@ -130,7 +182,7 @@ files:
130
182
  - lib/bwa/messages/control_configuration_request.rb
131
183
  - lib/bwa/messages/filter_cycles.rb
132
184
  - lib/bwa/messages/ready.rb
133
- - lib/bwa/messages/set_temperature.rb
185
+ - lib/bwa/messages/set_target_temperature.rb
134
186
  - lib/bwa/messages/set_temperature_scale.rb
135
187
  - lib/bwa/messages/set_time.rb
136
188
  - lib/bwa/messages/status.rb
@@ -141,7 +193,8 @@ files:
141
193
  homepage: https://github.com/ccutrer/bwa
142
194
  licenses:
143
195
  - MIT
144
- metadata: {}
196
+ metadata:
197
+ rubygems_mfa_required: 'true'
145
198
  post_install_message:
146
199
  rdoc_options: []
147
200
  require_paths:
@@ -150,7 +203,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
203
  requirements:
151
204
  - - ">="
152
205
  - !ruby/object:Gem::Version
153
- version: '0'
206
+ version: '2.5'
154
207
  required_rubygems_version: !ruby/object:Gem::Requirement
155
208
  requirements:
156
209
  - - ">="
data/bin/bwa_client DELETED
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bwa/client'
4
- require 'bwa/discovery'
5
-
6
- def watch(spa)
7
- loop do
8
- begin
9
- message = spa.poll
10
- next if message.is_a?(BWA::Messages::Ready)
11
- puts message.raw_data.unpack("H*").first.scan(/[0-9a-f]{2}/).join(' ')
12
- puts message.inspect
13
- if block_given?
14
- break if yield
15
- end
16
- rescue BWA::InvalidMessage => e
17
- puts e.message
18
- puts e.raw_data.unpack("H*").first.scan(/[0-9a-f]{2}/).join(' ')
19
- break
20
- end
21
- end
22
- end
23
-
24
- if ARGV.empty?
25
- spas = BWA::Discovery.discover
26
- if spas.empty?
27
- $stderr.puts "Could not find spa!"
28
- exit 1
29
- end
30
- spa_ip = spas.first.first
31
- else
32
- spa_ip = ARGV[0]
33
- end
34
-
35
- spa = BWA::Client.new(spa_ip)
36
-
37
- spa.request_configuration
38
- spa.request_control_info
39
- watch(spa) do
40
- spa.last_status
41
- end
42
-
43
- watch(spa)