renstar 0.1.2 → 0.2.1

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: 055f5f7d489740202bb43ffd7c91da02a79d83dc11102068bfd39a89d3241fd4
4
- data.tar.gz: 877706e9308701870991f47abbc773b0c70492b4635b4d310accc88fa043b0d9
3
+ metadata.gz: c893e454f0d89cfacea09754a34ce55b14b327a821131fa3f91519d4fb82d194
4
+ data.tar.gz: 8fea02226bfcd4ec43a170d10cf830ed86430e8ccff222ae81de34933215a8c6
5
5
  SHA512:
6
- metadata.gz: 482dce11029a7a92d7aae52d100244cf072a6475040a7902418c708bbe77ed87cb4de317841e3feb9a514609fe23573d81857b831dd9e752219b5136ae402462
7
- data.tar.gz: 9a6af8c214bdb41963a109a4da8638ba246b7a5f890327e5de0e87f08562404c5e032d74e807a42bbfb19fe05552f9ab39597015d4737c5a4b8697546b6bb119
6
+ metadata.gz: 66f8f9dd14a24154e426a77fb27bbf907390751e7291a36b88078b4be451b1e264095482b0d5336dfe587837d69e18cf0d573af2b00d65f13402e88b5b8f21d9
7
+ data.tar.gz: b80c4954be1b7ca521c7ccf0d630b84215e1480082cbd0deabe2408b964d21c72d509826366efc671c682f473e2e6250cbb23985b590a32b82bd5bcfab17487e
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/README.md CHANGED
@@ -60,7 +60,7 @@ thermo.fan_toggle
60
60
  ```ruby
61
61
  thermo.schedule_on
62
62
 
63
- thermo.scheduel_off
63
+ thermo.schedule_off
64
64
 
65
65
  thermo.schedule_toggle
66
66
  ```
data/bin/renstar.rb CHANGED
@@ -2,49 +2,41 @@ require 'renstar'
2
2
  require 'optparse'
3
3
  require 'ostruct'
4
4
 
5
- class RenstarOptions
6
- DEFAULT_OPTIONS = { all: false }.freeze
7
- USAGE = " Usage: renstar.rb command [value]"
5
+ options = {}
8
6
 
9
- def self.parse(args)
7
+ #DEFAULT_OPTIONS = { all: false }.freeze
10
8
 
11
- @options = OpenStruct.new(DEFAULT_OPTIONS)
12
9
 
13
- options = OptionParser.new do |opts|
14
- opts.banner = USAGE
10
+ USAGE = " Usage: renstar.rb command [value]"
15
11
 
16
- opts.on '-d', '--discover', 'Discover all Renstar devices' do |d|
17
- @options.discover = true
18
- end
12
+ OptionParser.new do |opts|
19
13
 
20
- opts.on '-h', '--help', 'Display this screen' do |h|
21
- @options.help = true
22
- end
23
- end
14
+ opts.banner = USAGE
24
15
 
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
16
+ opts.on '-d', '--discover', 'Discover all Renstar devices' do |d|
17
+ options[:discover] = true
18
+ end
40
19
 
20
+ opts.on '-h', '--help', 'Display this screen' do |h|
21
+ puts opts
22
+ exit 0
23
+ end
24
+ end.parse!
41
25
 
26
+ if options[:discover]
27
+ thermos = Renstar::Thermostat.search
28
+ thermos.each do |thermo|
29
+ puts "Found: #{thermo.location} #{thermo.usn}"
42
30
  end
31
+ exit 0
43
32
  end
44
33
 
45
- @options = RenstarOptions.parse(ARGV)
46
34
 
47
- thermo = Renstar::Thermostat.search.first
48
-
49
-
50
- thermo.send(*ARGV)
35
+ thermos = Renstar::Thermostat.search
36
+ thermos.each do |thermo|
37
+ puts "Found: #{thermo.location} #{thermo.usn}"
38
+ end
39
+ puts "Using: " + thermos.first.location + " - " + thermos.first.usn
40
+ unless (ARGV.nil? || ARGV.empty?)
41
+ puts thermos.first.send(*ARGV)
42
+ 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.2'
4
+ VERSION = '0.2.1'
5
5
  end
data/renstar.gemspec CHANGED
@@ -24,12 +24,12 @@ Gem::Specification.new do |spec|
24
24
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
25
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
26
26
  end
27
- spec.bindir = 'exe'
28
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.bindir = 'bin'
28
+ spec.executables = spec.files.grep(%r{\Abin/}) { |f| File.basename(f) }
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.1.2
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Rodrigues
8
8
  autorequire:
9
- bindir: exe
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
@@ -28,26 +28,28 @@ 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: '0'
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: '0'
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
44
- executables: []
44
+ executables:
45
+ - console
46
+ - renstar.rb
47
+ - setup
45
48
  extensions: []
46
49
  extra_rdoc_files: []
47
50
  files:
48
51
  - ".gitignore"
49
52
  - Gemfile
50
- - Gemfile.lock
51
53
  - LICENSE
52
54
  - README.md
53
55
  - 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