renstar 0.4.4 → 0.4.5
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 +2 -0
- data/bin/renstar.rb +7 -1
- data/lib/renstar/api_client.rb +13 -3
- data/lib/renstar/discovery.rb +1 -1
- data/lib/renstar/thermostat.rb +24 -20
- data/lib/renstar/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0af30640855c7d5568a2a8fbd16ac0f554f5bdf20415c5085974354120aedfd0
|
4
|
+
data.tar.gz: 04ddf28ef495cb77a1bfebe74d2ae508c9bac487f4eeb86bceddab6cbd2dd228
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b8c6e5eb3c7e8e31481d9689c29f01e26f945f89a95342460d2f0864b74c51f9b2003116af4644c5e7f796213db8d016db4706b513b630c70f4a005b41c84ec
|
7
|
+
data.tar.gz: 6afab4dc745a6a18da67f1ecfff3e5047aed24930c23a7d5208864947a780f758ee0fab0f733e5824262b62ae0e198e4663b0b200b835df580ed6ccfcc39e5c2
|
data/README.md
CHANGED
@@ -4,6 +4,8 @@ Renstar is a Ruby SDK for interacting with the Venstar Thermostat Local API.
|
|
4
4
|
|
5
5
|
You can control your thermostat programmatically!
|
6
6
|
|
7
|
+
[](https://codeclimate.com/github/mikerodrigues/renstar/maintainability)
|
8
|
+
|
7
9
|
## Installation
|
8
10
|
|
9
11
|
Add this line to your application's Gemfile:
|
data/bin/renstar.rb
CHANGED
@@ -83,7 +83,13 @@ command = if ARGV.nil? || ARGV.empty?
|
|
83
83
|
ARGV
|
84
84
|
end
|
85
85
|
|
86
|
-
|
86
|
+
begin
|
87
|
+
response = thermo.send(*command)
|
88
|
+
rescue NoMethodError
|
89
|
+
puts "'#{command.join(' ')}' is not a valid command"
|
90
|
+
exit 1
|
91
|
+
end
|
92
|
+
|
87
93
|
case response
|
88
94
|
when String
|
89
95
|
puts response
|
data/lib/renstar/api_client.rb
CHANGED
@@ -13,16 +13,26 @@ module Renstar
|
|
13
13
|
# The actual client that handles getting, posting, and parsing API responses
|
14
14
|
#
|
15
15
|
module APIClient
|
16
|
+
class APIError < StandardError; end
|
17
|
+
class APIUnknownResponseError < StandardError; end
|
18
|
+
|
16
19
|
def get(endpoint)
|
17
20
|
uri = URI(location + endpoint)
|
18
|
-
response = Net::HTTP.
|
19
|
-
JSON.parse(response)
|
21
|
+
response = Net::HTTP.get_response(uri)
|
22
|
+
JSON.parse(response.body)
|
20
23
|
end
|
21
24
|
|
22
25
|
def post(endpoint, options = {})
|
23
26
|
uri = URI(location + endpoint)
|
24
27
|
response = Net::HTTP.post_form(uri, options)
|
25
|
-
JSON.parse(response.body)
|
28
|
+
json = JSON.parse(response.body)
|
29
|
+
if json['error']
|
30
|
+
raise APIError, json['reason']
|
31
|
+
elsif json['success']
|
32
|
+
json
|
33
|
+
else
|
34
|
+
raise APIUnknownResponseError, response.body
|
35
|
+
end
|
26
36
|
end
|
27
37
|
|
28
38
|
include Query
|
data/lib/renstar/discovery.rb
CHANGED
@@ -22,7 +22,7 @@ module Renstar
|
|
22
22
|
def ssdp_search(ip, timeout = 5)
|
23
23
|
puts "Searching subnet associated with #{ip.ip_address}"
|
24
24
|
ssdp = SSDP::Consumer.new({ bind: ip.ip_address })
|
25
|
-
|
25
|
+
ssdp.search(service: SERVICE, timeout: timeout)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
data/lib/renstar/thermostat.rb
CHANGED
@@ -31,14 +31,12 @@ module Renstar
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def self.search(timeout = 3)
|
34
|
-
all_thermos =
|
35
|
-
ips.each do |ip|
|
34
|
+
all_thermos = ips.each do |ip|
|
36
35
|
all_thermos << ssdp_search(ip, timeout)
|
37
36
|
end
|
37
|
+
|
38
38
|
all_thermos.flatten.map do |thermo|
|
39
|
-
|
40
|
-
usn = thermo[:params]['USN']
|
41
|
-
Renstar::Thermostat.new(location, usn)
|
39
|
+
Renstar::Thermostat.new(thermo[:params]['Location'], thermo[:params]['USN'])
|
42
40
|
end
|
43
41
|
end
|
44
42
|
|
@@ -54,27 +52,14 @@ module Renstar
|
|
54
52
|
end
|
55
53
|
|
56
54
|
def heat(heattemp = nil)
|
57
|
-
|
58
|
-
if heattemp
|
59
|
-
cooltemp = heattemp.to_i + 1
|
60
|
-
else
|
61
|
-
cooltemp = @cached_info.cooltemp
|
62
|
-
heattemp = @cached_info.heattemp
|
63
|
-
end
|
55
|
+
cooltemp, heattemp = set_temps(heattemp, 1)
|
64
56
|
response = control("mode": 1, "cooltemp": cooltemp, "heattemp": heattemp)
|
65
57
|
update
|
66
58
|
response
|
67
59
|
end
|
68
60
|
|
69
61
|
def cool(cooltemp = nil)
|
70
|
-
|
71
|
-
if cooltemp
|
72
|
-
heattemp = cooltemp.to_i - 1
|
73
|
-
# heattemp = cooltemp - @cached_info.setpointdelta
|
74
|
-
else
|
75
|
-
cooltemp = @cached_info.cooltemp
|
76
|
-
heattemp = @cached_info.heattemp
|
77
|
-
end
|
62
|
+
cooltemp, heattemp = set_temps(cooltemp, 2)
|
78
63
|
response = control("mode": 2, "cooltemp": cooltemp, "heattemp": heattemp)
|
79
64
|
update
|
80
65
|
response
|
@@ -134,5 +119,24 @@ module Renstar
|
|
134
119
|
update
|
135
120
|
response
|
136
121
|
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
def set_temps(temp, mode)
|
126
|
+
update
|
127
|
+
if temp
|
128
|
+
if mode == 1
|
129
|
+
cooltemp = temp.to_i + 1
|
130
|
+
heattemp = temp.to_i
|
131
|
+
else
|
132
|
+
cooltemp = temp.to_i
|
133
|
+
heattemp = temp.to_i - 1
|
134
|
+
end
|
135
|
+
else
|
136
|
+
cooltemp = @cached_info.cooltemp
|
137
|
+
heattemp = @cached_info.heattemp
|
138
|
+
end
|
139
|
+
[cooltemp, heattemp]
|
140
|
+
end
|
137
141
|
end
|
138
142
|
end
|
data/lib/renstar/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: renstar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Rodrigues
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|