renstar 0.2.1 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c893e454f0d89cfacea09754a34ce55b14b327a821131fa3f91519d4fb82d194
4
- data.tar.gz: 8fea02226bfcd4ec43a170d10cf830ed86430e8ccff222ae81de34933215a8c6
3
+ metadata.gz: ec271b5f2fff4930b2689574a8dbffda3a7aa956ee2b251771cb3c37ea3eea99
4
+ data.tar.gz: c44ba6940104204e8cae7ba9531134e94fa22df79d39b224ae2a92968bcaf2e7
5
5
  SHA512:
6
- metadata.gz: 66f8f9dd14a24154e426a77fb27bbf907390751e7291a36b88078b4be451b1e264095482b0d5336dfe587837d69e18cf0d573af2b00d65f13402e88b5b8f21d9
7
- data.tar.gz: b80c4954be1b7ca521c7ccf0d630b84215e1480082cbd0deabe2408b964d21c72d509826366efc671c682f473e2e6250cbb23985b590a32b82bd5bcfab17487e
6
+ metadata.gz: 49c89698f8df31b6f6410af9ab6d0cf2607fb3c637aaa1bd0afb044a33393285614e31b679877e7a9bc6aecc258d830f512203a018adc0ab2b2e903ebeaac0c1
7
+ data.tar.gz: 92a4ca9dfc653a48bada22b2f0f8d658739b106e116f58ac96872724dc070c5cdb3341b5567c3a67c27c0dbbde42f249662fd81cfa83acd662bd39bedd4bebca
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.4
data/Gemfile CHANGED
@@ -6,4 +6,3 @@ source 'https://rubygems.org'
6
6
  gemspec
7
7
 
8
8
  gem 'rake', '~> 13.0'
9
- gem 'ssdp', git: 'https://github.com/mikerodrigues/ssdp'
data/README.md CHANGED
@@ -20,13 +20,74 @@ Or install it yourself as:
20
20
 
21
21
  $ gem install renstar
22
22
 
23
- ## Usage
23
+ ## Using the included binary
24
+
25
+ Well, OK, it's just a script that uses the library, but it wraps all of the
26
+ functionality and lets you just control your thermostat if that's all you're
27
+ here for.
28
+
29
+ When installing the gem, we install `renstar.rb` for you automatically. You can
30
+ pass the `-h` flag for more info.
31
+
32
+ The help page does not list all the accepted commands or their values but all of
33
+ the methods below are supported. The binary just passes your arguments to the
34
+ methods below.
35
+
36
+ So, if you want to cool your house to 72 using the binary, you can do this in
37
+ your favorite shell:
38
+ ```bash
39
+ renstar.rb cool 72
40
+ ```
41
+
42
+ You can apply the logic above to any of the methods below for the same effect.
43
+
44
+ ### Note about thermostat selection
45
+
46
+ The binary chooses the first thermostat it finds on the network, so you may get
47
+ unexpected results if you have more than one on your network.
48
+
49
+ You can use the `-t` option to pass the hostname or IP address of a thermostat
50
+ if you know it and don't want to wait for autodiscovery to find it.
51
+
52
+ ## Using the library
53
+
54
+ First we need to create a `Thermostat` object.
24
55
 
25
56
  * Search for thermostats on the LAN, return the first one found:
26
57
  ```ruby
27
58
  thermo = Renstar::Thermostat.search.first
28
59
  ```
29
60
 
61
+ ### Query
62
+
63
+ These methods let you see the thermostat info (controls and settings status), sensor info, runtimes, and
64
+ alerts.
65
+
66
+ * Get information about the thermostat:
67
+ ```ruby
68
+ thermo.info
69
+ ```
70
+
71
+ * Get the current sensors and their readings:
72
+ ```ruby
73
+ thermo.sensors
74
+ ```
75
+
76
+ * Get runtimes:
77
+ ```ruby
78
+ thermo.runtimes
79
+ ```
80
+
81
+ * See alerts and their status:
82
+ ```ruby
83
+ thermo.alerts
84
+ ```
85
+
86
+ ### Control
87
+
88
+ These methods let you control the thermostat temperature controls, and fan. You
89
+ can use the `info` method to check the current state of these controls.
90
+
30
91
  * Heat to 80 degrees:
31
92
  ```ruby
32
93
  thermo.heat(80)
@@ -42,7 +103,7 @@ thermo.cool(60)
42
103
  thermo.auto(70, 74)
43
104
  ```
44
105
 
45
- * Turn off heeating and/or cooling
106
+ * Turn off heating and/or cooling
46
107
  ```ruby
47
108
  thermo.off
48
109
  ```
@@ -56,7 +117,13 @@ thermo.fan_off
56
117
  thermo.fan_toggle
57
118
  ```
58
119
 
59
- * Control the schedule:
120
+ ### Settings
121
+
122
+ These methods let you change the schedule and vacation settings on your
123
+ thermostat. You can use the `info` method to check the current state of the
124
+ settings.
125
+
126
+ * Set the schedule:
60
127
  ```ruby
61
128
  thermo.schedule_on
62
129
 
@@ -72,8 +139,6 @@ thermo.home
72
139
  thermo.away
73
140
  ```
74
141
 
75
-
76
-
77
142
  ## Development
78
143
 
79
144
  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,42 +1,68 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'renstar'
2
4
  require 'optparse'
3
5
  require 'ostruct'
4
6
 
5
7
  options = {}
6
8
 
7
- #DEFAULT_OPTIONS = { all: false }.freeze
9
+ # DEFAULT_OPTIONS = { all: false }.freeze
8
10
 
11
+ USAGE = ' Usage: renstar.rb command [value]'
9
12
 
10
- USAGE = " Usage: renstar.rb command [value]"
13
+ Options = Struct.new(:thermostat)
14
+ args = Options.new
11
15
 
12
16
  OptionParser.new do |opts|
13
-
14
17
  opts.banner = USAGE
15
18
 
16
- opts.on '-d', '--discover', 'Discover all Renstar devices' do |d|
19
+ opts.on '-d', '--discover', 'Discover all Renstar devices' do |_d|
17
20
  options[:discover] = true
18
21
  end
19
22
 
20
- opts.on '-h', '--help', 'Display this screen' do |h|
23
+ opts.on '-h', '--help', 'Display this screen' do |_h|
21
24
  puts opts
22
25
  exit 0
23
26
  end
27
+
28
+ opts.on '-tTHERMOSTAT', '--thermostat=THERMOSTAT', 'Use thermostat by host name or IP. No discovery.' do |t|
29
+ args.thermostat = t
30
+ end
24
31
  end.parse!
25
32
 
26
33
  if options[:discover]
27
34
  thermos = Renstar::Thermostat.search
28
- thermos.each do |thermo|
29
- puts "Found: #{thermo.location} #{thermo.usn}"
35
+ thermos.each do |t|
36
+ puts "Found: #{t.location} #{t.usn}"
30
37
  end
31
38
  exit 0
32
39
  end
33
40
 
34
-
35
- thermos = Renstar::Thermostat.search
36
- thermos.each do |thermo|
37
- puts "Found: #{thermo.location} #{thermo.usn}"
41
+ thermo = nil
42
+ if args.thermostat
43
+ thermo = Renstar::Thermostat.new(args.thermostat)
44
+ puts "Using: #{thermo.location}"
45
+ else
46
+ thermos = Renstar::Thermostat.search
47
+ thermos.each do |t|
48
+ puts "Found: #{t.location} #{t.usn}"
49
+ end
50
+ thermo = thermos.first
51
+ puts "Using: #{thermo.location} - #{thermo.usn}"
38
52
  end
39
- puts "Using: " + thermos.first.location + " - " + thermos.first.usn
40
- unless (ARGV.nil? || ARGV.empty?)
41
- puts thermos.first.send(*ARGV)
53
+ command = nil
54
+ if ARGV.nil? || ARGV.empty?
55
+ command = 'info'
56
+ else
57
+ command = ARGV
58
+ end
59
+
60
+ response = thermo.send(*command)
61
+ case response
62
+ when String
63
+ puts response
64
+ when Renstar::APIClient::APIObject
65
+ response.pp
66
+ when Array
67
+ response.each(&:pp)
42
68
  end
@@ -23,18 +23,14 @@ 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('runtimes', key)
29
- formatted_value = APIClient.value_to_formatted('runtimes', key, value)
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
-
35
- def pp
36
- puts human_readable
37
- end
38
34
  end
39
35
  end
40
36
  end
@@ -8,6 +8,9 @@ module Renstar
8
8
  # These alerts are for Air filter, Service, and UV Lamp
9
9
  #
10
10
  class Alert < APIObject
11
+ def pp
12
+ puts human_readable('alerts')
13
+ end
11
14
  end
12
15
  end
13
16
  end
@@ -9,6 +9,9 @@ module Renstar
9
9
  # info response from the API for clean access.
10
10
  #
11
11
  class Info < APIObject
12
+ def pp
13
+ puts human_readable('info')
14
+ end
12
15
  end
13
16
  end
14
17
  end
@@ -8,6 +8,9 @@ module Renstar
8
8
  # Breaks down how much time the system spent in various states
9
9
  # like heating or cooling.
10
10
  class Runtime < APIObject
11
+ def pp
12
+ puts human_readable('runtimes')
13
+ end
11
14
  end
12
15
  end
13
16
  end
@@ -7,6 +7,9 @@ module Renstar
7
7
  # Represents an installed sensor in the system
8
8
  # Returns the value of the sensor
9
9
  class Sensor < APIObject
10
+ def pp
11
+ puts human_readable('sensors')
12
+ end
10
13
  end
11
14
  end
12
15
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../api_client'
4
3
  module Renstar
5
4
  module APIClient
6
5
  # Interface to the "Control" portion of the Venstar API
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../api_client'
4
3
  require_relative 'api_objects/info'
5
4
  require_relative 'api_objects/sensor'
6
5
  require_relative 'api_objects/runtime'
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../api_client'
4
3
  module Renstar
5
4
  module APIClient
6
5
  # Interface to the "Settings" portion of the API
@@ -12,6 +12,7 @@ module Renstar
12
12
  #
13
13
  class Thermostat
14
14
  SERVICE = 'venstar:thermostat:ecp'
15
+ USN_REGEX = /^(\w+):(\w+)+:((?:[0-9a-fA-F]{2}:?)+):name:(.*):type:(.*)/
15
16
  DEFAULT_TIMEOUT = 3
16
17
 
17
18
  attr_reader :location, :usn, :cached_info
@@ -19,12 +20,12 @@ module Renstar
19
20
  include APIClient
20
21
 
21
22
  def initialize(location, usn = nil)
22
- if location && usn then
23
+ if location && usn
23
24
  @location = location
24
25
  @usn = usn
25
26
  else
26
- @location = "http://" + location + '/'
27
- @usn = ""
27
+ @location = "http://#{location}/"
28
+ @usn = ''
28
29
  end
29
30
 
30
31
  @cache_timestamp = Time.now
@@ -39,7 +40,7 @@ module Renstar
39
40
  end
40
41
  ips.each do |ip|
41
42
  puts "Searching subnet associated with #{ip.ip_address}"
42
- ssdp = SSDP::Consumer.new({bind: ip.ip_address})
43
+ ssdp = SSDP::Consumer.new({ bind: ip.ip_address })
43
44
  thermos = ssdp.search(service: SERVICE, timeout: timeout)
44
45
  thermos.each do |thermo|
45
46
  location = thermo[:params]['Location']
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Renstar
4
- VERSION = '0.2.1'
4
+ VERSION = '0.4.0'
5
5
  end
data/renstar.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = 'https://github.com/mikerodrigues/renstar'
14
14
  spec.required_ruby_version = '>= 3.0.0'
15
15
 
16
- spec.metadata['allowed_push_host'] = "https://rubygems.org"
16
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
17
17
 
18
18
  spec.metadata['homepage_uri'] = spec.homepage
19
19
  spec.metadata['source_code_uri'] = 'https://github.com/mikerodrigues/renstar'
@@ -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', '~> 1.1.7'
32
+ spec.add_runtime_dependency 'ssdp', '~> 1.2.0'
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.2.1
4
+ version: 0.4.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: 2022-08-06 00:00:00.000000000 Z
11
+ date: 2022-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.1.7
33
+ version: 1.2.0
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: 1.1.7
40
+ version: 1.2.0
41
41
  description: Control Venstar thermostats with Ruby via their local API.
42
42
  email:
43
43
  - mikebrodrigues@gmail.com
@@ -49,6 +49,7 @@ extensions: []
49
49
  extra_rdoc_files: []
50
50
  files:
51
51
  - ".gitignore"
52
+ - ".ruby-version"
52
53
  - Gemfile
53
54
  - LICENSE
54
55
  - README.md
@@ -91,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
92
  - !ruby/object:Gem::Version
92
93
  version: '0'
93
94
  requirements: []
94
- rubygems_version: 3.2.22
95
+ rubygems_version: 3.2.33
95
96
  signing_key:
96
97
  specification_version: 4
97
98
  summary: Control Venstar thermostats.