sensi 0.0.3 → 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 +4 -4
- data/.byebug_history +66 -0
- data/.gitignore +2 -1
- data/.rspec +1 -0
- data/README.md +1 -1
- data/lib/sensi/hash_to_object.rb +19 -1
- data/lib/sensi/poll_response.rb +6 -1
- data/lib/sensi/thermostat.rb +133 -28
- data/lib/sensi/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 770c2a7369508fca70bf405ffc7339e5d4d199e3
|
4
|
+
data.tar.gz: 2696abe6fe7d07a34d986f569694b9cf76359dc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cd20e2e6fa05a39ed9239a3bb830ba9bacaefef6e94087d278169632de00bf04cfe84342699682330914deb1653ec8633022134b7ea74f53c16955809c40a58
|
7
|
+
data.tar.gz: 046e6e779ebed7ce0101f9849b5c543155cd81c09f61368818c0ec0deae9cedab2072cec4beef4b16c7c93e0ff264db1ea9c4c1997fe713763f935741c6c9faa
|
data/.byebug_history
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
cont
|
2
|
+
quit
|
3
|
+
response.send(data).class
|
4
|
+
hto.send(data).class
|
5
|
+
hto.respond_to?(data)
|
6
|
+
data
|
7
|
+
cont
|
8
|
+
data
|
9
|
+
cont
|
10
|
+
data
|
11
|
+
cont
|
12
|
+
data
|
13
|
+
quit
|
14
|
+
cont
|
15
|
+
response.send(data).class
|
16
|
+
cont
|
17
|
+
response.send(data).class
|
18
|
+
hto.send(data).class
|
19
|
+
data
|
20
|
+
cont
|
21
|
+
data
|
22
|
+
cont
|
23
|
+
hto.send(data).classc
|
24
|
+
data
|
25
|
+
cont
|
26
|
+
hto.send(data).class
|
27
|
+
hto.respond_to?(data)
|
28
|
+
data
|
29
|
+
cont
|
30
|
+
quit
|
31
|
+
self.disconnect
|
32
|
+
quit
|
33
|
+
cont
|
34
|
+
@response.m.class
|
35
|
+
@response.m.class == Sensi::PollResponse
|
36
|
+
@response.respond_to?(:m)
|
37
|
+
self.valid_response?
|
38
|
+
@response
|
39
|
+
cont
|
40
|
+
@response
|
41
|
+
cont
|
42
|
+
@response.m.class == Sensi::PollResponse
|
43
|
+
@respsonse.m.class == Sensi::PollResponse
|
44
|
+
@response.respond_to?(:m)
|
45
|
+
cont
|
46
|
+
@response.m.class
|
47
|
+
cont
|
48
|
+
@response.m.empty?
|
49
|
+
@response
|
50
|
+
self.valid_response?
|
51
|
+
next
|
52
|
+
step
|
53
|
+
self.valid_response?
|
54
|
+
t.valid_response?
|
55
|
+
quit
|
56
|
+
data.class
|
57
|
+
cont
|
58
|
+
data.class
|
59
|
+
data
|
60
|
+
datums
|
61
|
+
cont
|
62
|
+
self.c
|
63
|
+
self
|
64
|
+
t.c
|
65
|
+
datums
|
66
|
+
data
|
data/.gitignore
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/README.md
CHANGED
data/lib/sensi/hash_to_object.rb
CHANGED
@@ -7,7 +7,7 @@ module Sensi
|
|
7
7
|
|
8
8
|
TEST = {'C': 'abc', 'A': ["hi", {:should=>"see"}], 'M': ['on','off','shutdown'], 'D': {'hola': 'hello'}, num: 5}
|
9
9
|
|
10
|
-
def initialize(hash = TEST, debug = false)
|
10
|
+
def initialize(hash = TEST, debug = false, json = nil)
|
11
11
|
convert(hash, debug)
|
12
12
|
end
|
13
13
|
|
@@ -69,6 +69,24 @@ module Sensi
|
|
69
69
|
self.instance_variable_set("@#{k.underscore}", v)
|
70
70
|
end
|
71
71
|
|
72
|
+
def to_json
|
73
|
+
hash = {}
|
74
|
+
self.instance_variables.each do |var|
|
75
|
+
if var.is_a? HashToObject
|
76
|
+
hash[var] = self.instance_variable_get(var).to_json
|
77
|
+
else
|
78
|
+
hash[var] = self.instance_variable_get(var)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
hash.to_json
|
82
|
+
end
|
83
|
+
|
84
|
+
def from_json!(string)
|
85
|
+
JSON.load(string).each do |var, val|
|
86
|
+
self.instance_variable_set var, val
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
72
90
|
end
|
73
91
|
|
74
92
|
end
|
data/lib/sensi/poll_response.rb
CHANGED
@@ -5,11 +5,14 @@ module Sensi
|
|
5
5
|
|
6
6
|
class PollResponse < HashToObject
|
7
7
|
|
8
|
-
attr_reader :json
|
8
|
+
attr_reader :json, :code
|
9
9
|
|
10
10
|
def initialize(json)
|
11
11
|
@json = json
|
12
12
|
convert(json)
|
13
|
+
@code = 200
|
14
|
+
rescue
|
15
|
+
@code = 500
|
13
16
|
end
|
14
17
|
|
15
18
|
def message_id
|
@@ -18,6 +21,8 @@ module Sensi
|
|
18
21
|
|
19
22
|
def groups_token
|
20
23
|
self.g
|
24
|
+
rescue
|
25
|
+
nil
|
21
26
|
end
|
22
27
|
|
23
28
|
def timed_out?
|
data/lib/sensi/thermostat.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
require "sensi/version"
|
2
2
|
require 'sensi/hash_to_object'
|
3
3
|
require 'sensi/thermostat_connection'
|
4
|
+
require 'byebug'
|
4
5
|
|
5
6
|
module Sensi
|
6
7
|
|
7
8
|
class Thermostat < HashToObject
|
8
9
|
|
9
|
-
attr_accessor :account, :thermostat_connection
|
10
|
+
attr_accessor :account, :thermostat_connection, :response
|
10
11
|
|
11
12
|
@account
|
12
13
|
@thermostat_connection
|
14
|
+
@response
|
13
15
|
|
14
16
|
#private vars
|
15
17
|
@mode
|
@@ -18,7 +20,7 @@ module Sensi
|
|
18
20
|
@fan
|
19
21
|
@schedule
|
20
22
|
|
21
|
-
def initialize(login, password)
|
23
|
+
def initialize(login, password, json = nil)
|
22
24
|
@account = Sensi::Account.new(login, password)
|
23
25
|
@thermostat_connection = Sensi::ThermostatConnection.new(@account)
|
24
26
|
end
|
@@ -43,17 +45,12 @@ module Sensi
|
|
43
45
|
while not connected_to_device? and attempt < connection_attempt
|
44
46
|
@thermostat_connection.connect
|
45
47
|
@thermostat_connection.initialize_polling(self.icd)
|
46
|
-
|
48
|
+
@response = @thermostat_connection.start_polling
|
49
|
+
convert(@response)
|
47
50
|
attempt += 1
|
48
51
|
end
|
49
52
|
|
50
|
-
|
51
|
-
@cool = settings.cool_setpoint
|
52
|
-
@mode = system_mode
|
53
|
-
@schedule = nil
|
54
|
-
@fan = 'Auto'
|
55
|
-
|
56
|
-
return connected_to_device?
|
53
|
+
connected_to_device?
|
57
54
|
end
|
58
55
|
|
59
56
|
def connected_to_device?
|
@@ -62,10 +59,42 @@ module Sensi
|
|
62
59
|
false
|
63
60
|
end
|
64
61
|
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
|
62
|
+
def valid_response?
|
63
|
+
# debugger
|
64
|
+
@response.respond_to?(:m) and @response.m.class == Sensi::HashToObject
|
65
|
+
rescue StandardError
|
66
|
+
return false
|
67
|
+
end
|
68
|
+
|
69
|
+
def update(attempts = 3)
|
70
|
+
@response = nil
|
71
|
+
attempt = 0
|
72
|
+
# debugger
|
73
|
+
while attempt < attempts and not valid_response?
|
74
|
+
@response = @thermostat_connection.poll
|
75
|
+
attempt += 1
|
76
|
+
end
|
77
|
+
|
78
|
+
return false if @response.code != 200
|
79
|
+
|
80
|
+
update_self(self, @response) if valid_response?
|
81
|
+
!@response.timed_out? and valid_response?
|
82
|
+
end
|
83
|
+
|
84
|
+
def update_self(hto, response)
|
85
|
+
datums = (response.methods - Object.new.methods).reject!{|i| i.to_s =~ /=|\?|convert|contains_hash|add|json|message_id|groups_token/ }
|
86
|
+
datums.each do |data|
|
87
|
+
# debugger
|
88
|
+
if hto.respond_to?(data) and hto.send(data).class == Sensi::PollResponse and response.send(data).class == Sensi::PollResponse
|
89
|
+
update_self(hto.send(data), response.send(data))
|
90
|
+
elsif hto.respond_to?(data) and hto.send(data).class == Sensi::HashToObject and response.send(data).class == Sensi::HashToObject
|
91
|
+
update_self(hto.send(data), response.send(data))
|
92
|
+
elsif hto.respond_to?(data) and response.send(data).class == Sensi::PollResponse
|
93
|
+
hto.send((data.to_s + '=').to_sym, response.send(data))
|
94
|
+
else
|
95
|
+
hto.add_var(data.to_s, response.send(data))
|
96
|
+
end
|
97
|
+
end
|
69
98
|
end
|
70
99
|
|
71
100
|
def system_modes
|
@@ -90,7 +119,11 @@ module Sensi
|
|
90
119
|
"0"
|
91
120
|
end
|
92
121
|
|
93
|
-
def
|
122
|
+
def system_fan
|
123
|
+
self.m.a.environment_controls.fan_mode
|
124
|
+
end
|
125
|
+
|
126
|
+
def temperature(scale = :F)
|
94
127
|
case scale
|
95
128
|
when :F
|
96
129
|
return self.m.a.operational_status.temperature.f
|
@@ -106,11 +139,7 @@ module Sensi
|
|
106
139
|
end
|
107
140
|
|
108
141
|
def system_mode
|
109
|
-
self.m.a.
|
110
|
-
end
|
111
|
-
|
112
|
-
def system_fan
|
113
|
-
nil
|
142
|
+
self.m.a.environment_controls.system_mode
|
114
143
|
end
|
115
144
|
|
116
145
|
# def set(mode: nil, temp: 70, scale: :F, fan: :auto, schedule: :off)
|
@@ -124,13 +153,12 @@ module Sensi
|
|
124
153
|
args.each do |k, v|
|
125
154
|
case k
|
126
155
|
when :mode
|
127
|
-
|
156
|
+
# puts "#{system_mode}:#{v.to_s.capitalize}"
|
157
|
+
return update_system_mode v
|
128
158
|
when :fan
|
129
|
-
|
159
|
+
return update_fan v
|
130
160
|
when :temp
|
131
|
-
|
132
|
-
|
133
|
-
@thermostat_connection.set(self.icd, 'SetCool', v.to_s.capitalize, scale.to_s.capitalize) unless system_temperature(:cool) == temp
|
161
|
+
return update_temp v
|
134
162
|
when :schedule
|
135
163
|
@thermostat_connection.set(self.icd, 'SetScheduleMode', v.to_s.capitalize) unless system_schedule == args
|
136
164
|
end
|
@@ -178,14 +206,20 @@ module Sensi
|
|
178
206
|
system_mode =- 'Auto'
|
179
207
|
end
|
180
208
|
|
181
|
-
def
|
209
|
+
def system_active?
|
210
|
+
active_mode != 'Off'
|
211
|
+
end
|
212
|
+
|
213
|
+
def system_temperature(type: nil)
|
214
|
+
type = system_mode.downcase.to_sym if type.nil?
|
215
|
+
|
182
216
|
case type
|
183
217
|
when :heat
|
184
218
|
return settings.heat_setpoint.f
|
185
219
|
when :cool
|
186
220
|
return settings.cool_setpoint.f
|
187
221
|
else
|
188
|
-
raise ArgumentError, "Type
|
222
|
+
raise ArgumentError, "Type :#{type.to_s} not valid."
|
189
223
|
end
|
190
224
|
end
|
191
225
|
|
@@ -198,9 +232,80 @@ module Sensi
|
|
198
232
|
# end
|
199
233
|
|
200
234
|
def system_fan_on?
|
201
|
-
|
235
|
+
system_fan == 'On'
|
236
|
+
end
|
237
|
+
|
238
|
+
def system_fan_off?
|
239
|
+
system_fan == 'Auto'
|
240
|
+
end
|
241
|
+
|
242
|
+
def update_system_mode(state)
|
243
|
+
if system_mode == state.to_s.capitalize
|
244
|
+
return false
|
245
|
+
else
|
246
|
+
result = @thermostat_connection.set(self.icd, 'SetSystemMode', state.to_s.capitalize)
|
247
|
+
update
|
248
|
+
return result
|
249
|
+
end
|
202
250
|
end
|
203
251
|
|
252
|
+
def update_fan(state)
|
253
|
+
if system_fan == state.to_s.capitalize
|
254
|
+
return false
|
255
|
+
else
|
256
|
+
result = @thermostat_connection.set(self.icd, 'SetFanMode', state.to_s.capitalize)
|
257
|
+
update
|
258
|
+
return result
|
259
|
+
end
|
260
|
+
# case state
|
261
|
+
# when 'On'
|
262
|
+
# return @thermostat_connection.set(self.icd, 'SetFanMode', state.to_s.capitalize) unless system_fan_on?
|
263
|
+
# when 'Auto'
|
264
|
+
# return @thermostat_connection.set(self.icd, 'SetFanMode', state.to_s.capitalize) unless system_fan_off?
|
265
|
+
# else
|
266
|
+
# raise StandarError, "#{v} is not a valid fan state."
|
267
|
+
# end
|
268
|
+
end
|
269
|
+
|
270
|
+
def update_temp(temperature, mode: nil, scale: :F)
|
271
|
+
mode = system_mode if mode.nil?
|
272
|
+
|
273
|
+
case mode
|
274
|
+
when 'Heat'
|
275
|
+
return true if system_temperature(type: :heat) == temperature
|
276
|
+
result = @thermostat_connection.set(self.icd, 'SetHeat', temperature.to_s.capitalize, scale.to_s.capitalize)
|
277
|
+
when 'Cool'
|
278
|
+
return true if system_temperature(type: :cool) == temperature
|
279
|
+
result = @thermostat_connection.set(self.icd, 'SetCool', temperature.to_s.capitalize, scale.to_s.capitalize)
|
280
|
+
when 'Off'
|
281
|
+
|
282
|
+
when 'Auto'
|
283
|
+
|
284
|
+
when 'Aux'
|
285
|
+
|
286
|
+
end
|
287
|
+
update
|
288
|
+
result
|
289
|
+
end
|
290
|
+
|
291
|
+
def to_json
|
292
|
+
hash = {}
|
293
|
+
self.instance_variables.each do |var|
|
294
|
+
if var.is_a? HashToObject
|
295
|
+
hash[var.to_s.delete("@")] = self.instance_variable_get var.to_json
|
296
|
+
else
|
297
|
+
hash[var.to_s.delete("@")] = self.instance_variable_get var
|
298
|
+
end
|
299
|
+
end
|
300
|
+
hash.to_json
|
301
|
+
end
|
302
|
+
|
303
|
+
def from_json!(string)
|
304
|
+
JSON.load(string).each do |var, val|
|
305
|
+
self.instance_variable_set var, val
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
204
309
|
|
205
310
|
end
|
206
311
|
|
data/lib/sensi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Kirby
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03
|
11
|
+
date: 2016-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -87,7 +87,9 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
+
- ".byebug_history"
|
90
91
|
- ".gitignore"
|
92
|
+
- ".rspec"
|
91
93
|
- CODE_OF_CONDUCT.md
|
92
94
|
- Gemfile
|
93
95
|
- LICENSE.txt
|