renstar 0.4.3 → 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 +2 -16
- data/lib/renstar/thermostat.rb +31 -15
- 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
@@ -8,17 +8,8 @@ module Renstar
|
|
8
8
|
# the network
|
9
9
|
module Discovery
|
10
10
|
# Discovery timeout when searching for thermostats
|
11
|
-
DEFAULT_TIMEOUT = 3
|
12
11
|
SERVICE = 'venstar:thermostat:ecp'
|
13
12
|
|
14
|
-
def search(timeout = DEFAULT_TIMEOUT)
|
15
|
-
all_thermos = []
|
16
|
-
ips.each do |ip|
|
17
|
-
all_thermos << ssdp_search(ip, timeout)
|
18
|
-
end
|
19
|
-
all_thermos.flatten
|
20
|
-
end
|
21
|
-
|
22
13
|
private
|
23
14
|
|
24
15
|
def ips
|
@@ -28,15 +19,10 @@ module Renstar
|
|
28
19
|
end
|
29
20
|
|
30
21
|
# do an SSDP search using the given IP from a found local interface
|
31
|
-
def ssdp_search(ip, timeout =
|
22
|
+
def ssdp_search(ip, timeout = 5)
|
32
23
|
puts "Searching subnet associated with #{ip.ip_address}"
|
33
24
|
ssdp = SSDP::Consumer.new({ bind: ip.ip_address })
|
34
|
-
|
35
|
-
thermos.map do |thermo|
|
36
|
-
location = thermo[:params]['Location']
|
37
|
-
usn = thermo[:params]['USN']
|
38
|
-
Renstar::Thermostat.new(location, usn)
|
39
|
-
end
|
25
|
+
ssdp.search(service: SERVICE, timeout: timeout)
|
40
26
|
end
|
41
27
|
end
|
42
28
|
end
|
data/lib/renstar/thermostat.rb
CHANGED
@@ -30,6 +30,16 @@ module Renstar
|
|
30
30
|
@cached_info = info
|
31
31
|
end
|
32
32
|
|
33
|
+
def self.search(timeout = 3)
|
34
|
+
all_thermos = ips.each do |ip|
|
35
|
+
all_thermos << ssdp_search(ip, timeout)
|
36
|
+
end
|
37
|
+
|
38
|
+
all_thermos.flatten.map do |thermo|
|
39
|
+
Renstar::Thermostat.new(thermo[:params]['Location'], thermo[:params]['USN'])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
33
43
|
def update
|
34
44
|
@cache_timestamp = Time.now
|
35
45
|
@cached_info = info
|
@@ -42,27 +52,14 @@ module Renstar
|
|
42
52
|
end
|
43
53
|
|
44
54
|
def heat(heattemp = nil)
|
45
|
-
|
46
|
-
if heattemp
|
47
|
-
cooltemp = heattemp.to_i + 1
|
48
|
-
else
|
49
|
-
cooltemp = @cached_info.cooltemp
|
50
|
-
heattemp = @cached_info.heattemp
|
51
|
-
end
|
55
|
+
cooltemp, heattemp = set_temps(heattemp, 1)
|
52
56
|
response = control("mode": 1, "cooltemp": cooltemp, "heattemp": heattemp)
|
53
57
|
update
|
54
58
|
response
|
55
59
|
end
|
56
60
|
|
57
61
|
def cool(cooltemp = nil)
|
58
|
-
|
59
|
-
if cooltemp
|
60
|
-
heattemp = cooltemp.to_i - 1
|
61
|
-
# heattemp = cooltemp - @cached_info.setpointdelta
|
62
|
-
else
|
63
|
-
cooltemp = @cached_info.cooltemp
|
64
|
-
heattemp = @cached_info.heattemp
|
65
|
-
end
|
62
|
+
cooltemp, heattemp = set_temps(cooltemp, 2)
|
66
63
|
response = control("mode": 2, "cooltemp": cooltemp, "heattemp": heattemp)
|
67
64
|
update
|
68
65
|
response
|
@@ -122,5 +119,24 @@ module Renstar
|
|
122
119
|
update
|
123
120
|
response
|
124
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
|
125
141
|
end
|
126
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
|