renstar 0.1.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +66 -6
- data/bin/renstar.rb +35 -34
- data/lib/renstar/api_client/api_object.rb +3 -6
- data/lib/renstar/api_client/api_objects/alert.rb +3 -0
- data/lib/renstar/api_client/api_objects/info.rb +3 -0
- data/lib/renstar/api_client/api_objects/runtime.rb +3 -0
- data/lib/renstar/api_client/api_objects/sensor.rb +3 -0
- data/lib/renstar/thermostat.rb +26 -10
- data/lib/renstar/version.rb +1 -1
- data/renstar.gemspec +1 -1
- metadata +7 -8
- data/Gemfile.lock +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e0023780425b4b2d649ffaaf881630adb1485a8c54e58934f69c31ba4953bd5
|
4
|
+
data.tar.gz: ebbef10e2b31c0c51aa5de4c8b02b82ec6f5d29be6d4526f4ec15c5cbdffde62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d36ebe45f2767dc4ed9f45f1299828004985fffe6c790913e5a1fad386ba23a59fd25347bb746ce0a2f9d8a88a448c952bfa707d77cfed9522e131477fc6f968
|
7
|
+
data.tar.gz: 4ae3c1982c6df2f82e05f45410002259df1a8c21113039dc4d9d4b2484819d432e2584109eb72683a3684e46d55519fe79b3342047904a32c68c7dae5c97db9f
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -20,13 +20,69 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
$ gem install renstar
|
22
22
|
|
23
|
-
##
|
23
|
+
## Using the included binary
|
24
|
+
|
25
|
+
When installing the gem, we install `renstar.rb` for you automatically. You can
|
26
|
+
pass the `-h` flag for more info.
|
27
|
+
|
28
|
+
The help page does not list all the accepted commands or their values but all of
|
29
|
+
the methods below are supported. The binary just passes your arguments to the
|
30
|
+
methods below.
|
31
|
+
|
32
|
+
So, if you want to cool your house to 72 using the binary, you can do this:
|
33
|
+
```ruby
|
34
|
+
renstar.rb cool 72
|
35
|
+
```
|
36
|
+
|
37
|
+
You can apply the logic above to any of the methods below for the same effect.
|
38
|
+
|
39
|
+
The binary chooses the first thermostat it finds on the network, so you may get
|
40
|
+
unexpected results if you have more than one on your network. I do plan on
|
41
|
+
improving this.
|
42
|
+
|
43
|
+
You may have trouble with discovery on multi-homed hosts, but I'm working with
|
44
|
+
the author of the `ssdp` library to fix this, so I expect it to improve. You can
|
45
|
+
install my fork of `ssdp` from github if you need multi-homed support now.
|
46
|
+
|
47
|
+
## Using the library
|
48
|
+
|
49
|
+
First we need to create a `Thermostat` object.
|
24
50
|
|
25
51
|
* Search for thermostats on the LAN, return the first one found:
|
26
52
|
```ruby
|
27
53
|
thermo = Renstar::Thermostat.search.first
|
28
54
|
```
|
29
55
|
|
56
|
+
### Query
|
57
|
+
|
58
|
+
These methods let you see the thermostat info (controls and settings status), sensor info, runtimes, and
|
59
|
+
alerts.
|
60
|
+
|
61
|
+
* Get information about the thermostat:
|
62
|
+
```ruby
|
63
|
+
thermo.info
|
64
|
+
```
|
65
|
+
|
66
|
+
* Get the current sensors and their readings:
|
67
|
+
```ruby
|
68
|
+
thermo.sensors
|
69
|
+
```
|
70
|
+
|
71
|
+
* Get runtimes:
|
72
|
+
```ruby
|
73
|
+
thermo.runtimes
|
74
|
+
```
|
75
|
+
|
76
|
+
* See alerts and their status:
|
77
|
+
```ruby
|
78
|
+
thermo.alerts
|
79
|
+
|
80
|
+
|
81
|
+
### Control
|
82
|
+
|
83
|
+
These methods let you control the thermostat temperature controls, and fan. You
|
84
|
+
can use the `info` method to check the current state of these controls.
|
85
|
+
|
30
86
|
* Heat to 80 degrees:
|
31
87
|
```ruby
|
32
88
|
thermo.heat(80)
|
@@ -42,7 +98,7 @@ thermo.cool(60)
|
|
42
98
|
thermo.auto(70, 74)
|
43
99
|
```
|
44
100
|
|
45
|
-
* Turn off
|
101
|
+
* Turn off heating and/or cooling
|
46
102
|
```ruby
|
47
103
|
thermo.off
|
48
104
|
```
|
@@ -56,11 +112,17 @@ thermo.fan_off
|
|
56
112
|
thermo.fan_toggle
|
57
113
|
```
|
58
114
|
|
59
|
-
|
115
|
+
### Settings
|
116
|
+
|
117
|
+
These methods let you change the schedule and vacation settings on your
|
118
|
+
thermostat. You can use the `info` method to check the current state of the
|
119
|
+
settings.
|
120
|
+
|
121
|
+
* Set the schedule:
|
60
122
|
```ruby
|
61
123
|
thermo.schedule_on
|
62
124
|
|
63
|
-
thermo.
|
125
|
+
thermo.schedule_off
|
64
126
|
|
65
127
|
thermo.schedule_toggle
|
66
128
|
```
|
@@ -72,8 +134,6 @@ thermo.home
|
|
72
134
|
thermo.away
|
73
135
|
```
|
74
136
|
|
75
|
-
|
76
|
-
|
77
137
|
## Development
|
78
138
|
|
79
139
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/bin/renstar.rb
CHANGED
@@ -1,50 +1,51 @@
|
|
1
1
|
require 'renstar'
|
2
2
|
require 'optparse'
|
3
3
|
require 'ostruct'
|
4
|
+
require 'pry'
|
4
5
|
|
5
|
-
|
6
|
-
DEFAULT_OPTIONS = { all: false }.freeze
|
7
|
-
USAGE = " Usage: renstar.rb command [value]"
|
6
|
+
options = {}
|
8
7
|
|
9
|
-
|
8
|
+
#DEFAULT_OPTIONS = { all: false }.freeze
|
10
9
|
|
11
|
-
@options = OpenStruct.new(DEFAULT_OPTIONS)
|
12
10
|
|
13
|
-
|
14
|
-
opts.banner = USAGE
|
11
|
+
USAGE = " Usage: renstar.rb command [value]"
|
15
12
|
|
16
|
-
|
17
|
-
@options.discover = true
|
18
|
-
end
|
13
|
+
OptionParser.new do |opts|
|
19
14
|
|
20
|
-
|
21
|
-
@options.help = true
|
22
|
-
end
|
23
|
-
end
|
15
|
+
opts.banner = USAGE
|
24
16
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
if @options.discover
|
30
|
-
Renstar.discover.each do |device|
|
31
|
-
puts "#{device.name} #{device.ip}"
|
32
|
-
end
|
33
|
-
exit 0
|
34
|
-
end
|
35
|
-
|
36
|
-
if @options.help
|
37
|
-
puts opts
|
38
|
-
exit 0
|
39
|
-
end
|
17
|
+
opts.on '-d', '--discover', 'Discover all Renstar devices' do |d|
|
18
|
+
options[:discover] = true
|
19
|
+
end
|
40
20
|
|
21
|
+
opts.on '-h', '--help', 'Display this screen' do |h|
|
22
|
+
puts opts
|
23
|
+
exit 0
|
24
|
+
end
|
25
|
+
end.parse!
|
41
26
|
|
27
|
+
if options[:discover]
|
28
|
+
thermos = Renstar::Thermostat.search
|
29
|
+
thermos.each do |thermo|
|
30
|
+
puts "Found: #{thermo.location} #{thermo.usn}"
|
42
31
|
end
|
32
|
+
exit 0
|
43
33
|
end
|
44
34
|
|
45
|
-
@options = RenstarOptions.parse(ARGV)
|
46
35
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
36
|
+
thermos = Renstar::Thermostat.search
|
37
|
+
thermos.each do |thermo|
|
38
|
+
puts "Found: #{thermo.location} #{thermo.usn}"
|
39
|
+
end
|
40
|
+
puts "Using: " + thermos.first.location + " - " + thermos.first.usn
|
41
|
+
unless (ARGV.nil? || ARGV.empty?)
|
42
|
+
response = thermos.first.send(*ARGV)
|
43
|
+
case response
|
44
|
+
when String
|
45
|
+
puts response
|
46
|
+
when Renstar::APIClient::APIObject
|
47
|
+
response.pp
|
48
|
+
when Array
|
49
|
+
response.each {|x| x.pp }
|
50
|
+
end
|
51
|
+
end
|
@@ -23,18 +23,15 @@ module Renstar
|
|
23
23
|
@raw_hash
|
24
24
|
end
|
25
25
|
|
26
|
-
def human_readable
|
26
|
+
def human_readable(type)
|
27
27
|
@raw_hash.map do |key, value|
|
28
|
-
description = APIClient.key_to_description(
|
29
|
-
formatted_value = APIClient.value_to_formatted(
|
28
|
+
description = APIClient.key_to_description(type, key)
|
29
|
+
formatted_value = APIClient.value_to_formatted(type, key, value)
|
30
30
|
format("%-35<description>s %<formatted_value>s\n",
|
31
31
|
{ description: description, formatted_value: formatted_value })
|
32
32
|
end.join
|
33
33
|
end
|
34
34
|
|
35
|
-
def pp
|
36
|
-
puts human_readable
|
37
|
-
end
|
38
35
|
end
|
39
36
|
end
|
40
37
|
end
|
data/lib/renstar/thermostat.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'ssdp'
|
4
|
+
require 'socket'
|
4
5
|
require_relative 'api_client'
|
5
6
|
|
6
7
|
module Renstar
|
@@ -11,27 +12,42 @@ module Renstar
|
|
11
12
|
#
|
12
13
|
class Thermostat
|
13
14
|
SERVICE = 'venstar:thermostat:ecp'
|
14
|
-
DEFAULT_TIMEOUT =
|
15
|
+
DEFAULT_TIMEOUT = 3
|
15
16
|
|
16
17
|
attr_reader :location, :usn, :cached_info
|
17
18
|
|
18
19
|
include APIClient
|
19
20
|
|
20
|
-
def initialize(location, usn)
|
21
|
-
|
22
|
-
|
21
|
+
def initialize(location, usn = nil)
|
22
|
+
if location && usn then
|
23
|
+
@location = location
|
24
|
+
@usn = usn
|
25
|
+
else
|
26
|
+
@location = "http://" + location + '/'
|
27
|
+
@usn = ""
|
28
|
+
end
|
29
|
+
|
23
30
|
@cache_timestamp = Time.now
|
24
31
|
@cached_info = info
|
25
32
|
end
|
26
33
|
|
27
34
|
def self.search(timeout = DEFAULT_TIMEOUT)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
35
|
+
all_thermos = []
|
36
|
+
ips = Socket.ip_address_list.select do |ip|
|
37
|
+
ip.ipv4? &&
|
38
|
+
!ip.ipv4_loopback?
|
39
|
+
end
|
40
|
+
ips.each do |ip|
|
41
|
+
puts "Searching subnet associated with #{ip.ip_address}"
|
42
|
+
ssdp = SSDP::Consumer.new({bind: ip.ip_address})
|
43
|
+
thermos = ssdp.search(service: SERVICE, timeout: timeout)
|
44
|
+
thermos.each do |thermo|
|
45
|
+
location = thermo[:params]['Location']
|
46
|
+
usn = thermo[:params]['USN']
|
47
|
+
all_thermos << Renstar::Thermostat.new(location, usn)
|
48
|
+
end
|
34
49
|
end
|
50
|
+
all_thermos
|
35
51
|
end
|
36
52
|
|
37
53
|
def update
|
data/lib/renstar/version.rb
CHANGED
data/renstar.gemspec
CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.require_paths = ['lib']
|
30
30
|
|
31
31
|
spec.add_runtime_dependency 'json'
|
32
|
-
spec.add_runtime_dependency 'ssdp'
|
32
|
+
spec.add_runtime_dependency 'ssdp', '~> 1.1.7'
|
33
33
|
|
34
34
|
# Uncomment to register a new dependency of your gem
|
35
35
|
# spec.add_dependency "example-gem", "~> 1.0"
|
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
|
+
version: 0.3.0
|
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: 2022-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: ssdp
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.1.7
|
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:
|
40
|
+
version: 1.1.7
|
41
41
|
description: Control Venstar thermostats with Ruby via their local API.
|
42
42
|
email:
|
43
43
|
- mikebrodrigues@gmail.com
|
@@ -50,7 +50,6 @@ extra_rdoc_files: []
|
|
50
50
|
files:
|
51
51
|
- ".gitignore"
|
52
52
|
- Gemfile
|
53
|
-
- Gemfile.lock
|
54
53
|
- LICENSE
|
55
54
|
- README.md
|
56
55
|
- Rakefile
|
@@ -92,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
91
|
- !ruby/object:Gem::Version
|
93
92
|
version: '0'
|
94
93
|
requirements: []
|
95
|
-
rubygems_version: 3.2.
|
94
|
+
rubygems_version: 3.2.33
|
96
95
|
signing_key:
|
97
96
|
specification_version: 4
|
98
97
|
summary: Control Venstar thermostats.
|
data/Gemfile.lock
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
renstar (0.1.1)
|
5
|
-
json
|
6
|
-
ssdp
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
json (2.6.1)
|
12
|
-
rake (13.0.6)
|
13
|
-
ssdp (1.1.7)
|
14
|
-
|
15
|
-
PLATFORMS
|
16
|
-
x86_64-linux
|
17
|
-
|
18
|
-
DEPENDENCIES
|
19
|
-
rake (~> 13.0)
|
20
|
-
renstar!
|
21
|
-
|
22
|
-
BUNDLED WITH
|
23
|
-
2.2.22
|