renstar 0.1.3 → 0.2.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: 3651f4b220453c1382ee4accc5503a1122364672acee6590366adcfe0bc911c9
4
- data.tar.gz: 7355ee293bca9e280004a799198c107c060c555dfff9913215c757d678ef67cc
3
+ metadata.gz: 395939a21c7674830297c4b637980c6b0ef8dd5a368ac9c7f22046e8acd30f8d
4
+ data.tar.gz: 76fcd3f4913478ca1993f8b0b9acfd27ab420f23005f55803a98955d5b196a5a
5
5
  SHA512:
6
- metadata.gz: d216511fa715d06164f923d0d923312d7c515f7c97f9395bb91fa90dec0cbc416fbcc935e338d4b08b20f518236a4a3bc55a8766d470c1b2a501fedb1ee67884
7
- data.tar.gz: 56077d08ddc62d53d365999ac75fe552aeb8cf52222f97b3ba8fe4ce5de9a9ebc0f04546803fbb9df422ae51187bff0cc20ae30e682dbdfb3f2bce6cc647df14
6
+ metadata.gz: 85342777ce38973500afc97c66c059c3b8b0e6b023367902d2271b3ece751a2f40c9840fc44e27c792fdf08a86f41467494e07aecc86dfbaa481b6cf471fd2c5
7
+ data.tar.gz: a30e766bb836c2e682f3f4b4499d8e77aea7cb7cb90e1ac44c8a61398df9e0657223b7e136ccf27cc8512bace3cec41e80e7f238247f6576774b414503194bbb
data/Gemfile CHANGED
@@ -6,3 +6,4 @@ 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/bin/renstar.rb CHANGED
@@ -1,50 +1,43 @@
1
1
  require 'renstar'
2
2
  require 'optparse'
3
3
  require 'ostruct'
4
+ require 'pry'
4
5
 
5
- class RenstarOptions
6
- DEFAULT_OPTIONS = { all: false }.freeze
7
- USAGE = " Usage: renstar.rb command [value]"
6
+ options = {}
8
7
 
9
- def self.parse(args)
8
+ #DEFAULT_OPTIONS = { all: false }.freeze
10
9
 
11
- @options = OpenStruct.new(DEFAULT_OPTIONS)
12
10
 
13
- options = OptionParser.new do |opts|
14
- opts.banner = USAGE
11
+ USAGE = " Usage: renstar.rb command [value]"
15
12
 
16
- opts.on '-d', '--discover', 'Discover all Renstar devices' do |d|
17
- @options.discover = true
18
- end
13
+ OptionParser.new do |opts|
19
14
 
20
- opts.on '-h', '--help', 'Display this screen' do |h|
21
- @options.help = true
22
- end
23
- end
15
+ opts.banner = USAGE
24
16
 
25
- options.parse!(args)
26
-
27
- puts options if @options && ARGV == []
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
- thermo = Renstar::Thermostat.search.first
48
-
49
-
50
- thermo.send(*ARGV)
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
+ puts thermos.first.send(*ARGV)
43
+ end
@@ -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 = 5
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
- @location = location
22
- @usn = usn
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
- ssdp = SSDP::Consumer.new
29
- thermos = ssdp.search(service: SERVICE, timeout: timeout)
30
- thermos.map do |thermo|
31
- location = thermo[:params]['Location']
32
- usn = thermo[:params]['USN']
33
- Renstar::Thermostat.new(location, usn)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Renstar
4
- VERSION = '0.1.3'
4
+ VERSION = '0.2.0'
5
5
  end
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'
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.1.3
4
+ version: 0.2.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: 2021-11-21 00:00:00.000000000 Z
11
+ date: 2022-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: ssdp
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  description: Control Venstar thermostats with Ruby via their local API.
42
28
  email:
43
29
  - mikebrodrigues@gmail.com
@@ -50,7 +36,6 @@ extra_rdoc_files: []
50
36
  files:
51
37
  - ".gitignore"
52
38
  - Gemfile
53
- - Gemfile.lock
54
39
  - LICENSE
55
40
  - README.md
56
41
  - Rakefile
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