renstar 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4646094a81dc4998ee000f134956818fac7b791ce68ec11654e81418ac43cc37
4
- data.tar.gz: adbc5a003a2111cc658ab34abc4a5abbe998c8b1a8b4899159326690cee56f79
3
+ metadata.gz: 395939a21c7674830297c4b637980c6b0ef8dd5a368ac9c7f22046e8acd30f8d
4
+ data.tar.gz: 76fcd3f4913478ca1993f8b0b9acfd27ab420f23005f55803a98955d5b196a5a
5
5
  SHA512:
6
- metadata.gz: 3323a727b6bcaed8b2636e39c602f48774c67f87066d19237ac4e26802e3bebec89ab793c4405d371d1c27ce9654dff52c4cb6d1ae46b2e78ca93e91d6aab518
7
- data.tar.gz: 66976f17ccf6a9672579d08e33019866744f9bc7e9897b9815db6e5649fcb2f4985f807ad35a04cc8ad5e2c737828932a1c8f9c7a5bee5a63ef2ec3f80511315
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 ADDED
@@ -0,0 +1,43 @@
1
+ require 'renstar'
2
+ require 'optparse'
3
+ require 'ostruct'
4
+ require 'pry'
5
+
6
+ options = {}
7
+
8
+ #DEFAULT_OPTIONS = { all: false }.freeze
9
+
10
+
11
+ USAGE = " Usage: renstar.rb command [value]"
12
+
13
+ OptionParser.new do |opts|
14
+
15
+ opts.banner = USAGE
16
+
17
+ opts.on '-d', '--discover', 'Discover all Renstar devices' do |d|
18
+ options[:discover] = true
19
+ end
20
+
21
+ opts.on '-h', '--help', 'Display this screen' do |h|
22
+ puts opts
23
+ exit 0
24
+ end
25
+ end.parse!
26
+
27
+ if options[:discover]
28
+ thermos = Renstar::Thermostat.search
29
+ thermos.each do |thermo|
30
+ puts "Found: #{thermo.location} #{thermo.usn}"
31
+ end
32
+ exit 0
33
+ end
34
+
35
+
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
@@ -48,7 +64,7 @@ module Renstar
48
64
  def heat(heattemp = nil)
49
65
  update
50
66
  if heattemp
51
- cooltemp = heattemp + 1.0
67
+ cooltemp = heattemp.to_i + 1
52
68
  else
53
69
  cooltemp = @cached_info.cooltemp
54
70
  heattemp = @cached_info.heattemp
@@ -61,7 +77,7 @@ module Renstar
61
77
  def cool(cooltemp = nil)
62
78
  update
63
79
  if cooltemp
64
- heattemp = cooltemp - 1.0
80
+ heattemp = cooltemp.to_i - 1
65
81
  # heattemp = cooltemp - @cached_info.setpointdelta
66
82
  else
67
83
  cooltemp = @cached_info.cooltemp
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Renstar
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.0'
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'
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.1
4
+ version: 0.2.0
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-10-30 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,34 +24,23 @@ 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
44
- executables: []
30
+ executables:
31
+ - console
32
+ - renstar.rb
33
+ - setup
45
34
  extensions: []
46
35
  extra_rdoc_files: []
47
36
  files:
48
37
  - ".gitignore"
49
38
  - Gemfile
50
- - Gemfile.lock
51
39
  - LICENSE
52
40
  - README.md
53
41
  - Rakefile
54
42
  - bin/console
43
+ - bin/renstar.rb
55
44
  - bin/setup
56
45
  - lib/renstar.rb
57
46
  - lib/renstar/api_client.rb
data/Gemfile.lock DELETED
@@ -1,23 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- renstar (0.1.0)
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