renstar 0.4.2 → 0.4.4

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: 3e5616f678e47e9b94cf668ce0cab8113c189ed175ab6fd63861e9a9462f2c0f
4
- data.tar.gz: 3c230f555fe5d49e65c62c0f5db24f3ac1c3dd5e5a9e7cb277c063eaa1789ee3
3
+ metadata.gz: e5990b28a9195f211562ebc90e3164440e0a8e401272fa87c7d9a3f0bf8636a4
4
+ data.tar.gz: de3c2bc468511bbc4ce4e57030883996384a83572a70fa649fb882980318a78f
5
5
  SHA512:
6
- metadata.gz: c5935c4649ea5130d532b795b56bafb9b70e76c492bf41418672c84bbeea4252e2e13c5af377a564e3e7662852fc4a74617708e3375f993165df712a9f5a9c40
7
- data.tar.gz: ea4900440f14c200f5dd941b2e9a46286e0573b86b461bd17bd20b37cf920d73d9a5b025d615317e64176a1a8d601926560d00df4df5dbb492a0922316a00d89
6
+ metadata.gz: '08cb4e79d6675044dad081a517a5efd9c683b80e593f566459202084c35962f7c37c7f92448cad5d1a957a1753d972de8cbb7ca96e08db0d86716701af1aec6c'
7
+ data.tar.gz: 70a6044088c34b6a0c56d410cc63a1bfee460b6a4c2290846d09f03ed9263504f33c2b1706228e459a2be233de1e0a55439aa6a824b7047d2cc7721950ceb51d
data/bin/renstar.rb CHANGED
@@ -8,14 +8,14 @@ options = {}
8
8
 
9
9
  # DEFAULT_OPTIONS = { all: false }.freeze
10
10
 
11
- USAGE = ''' Usage: renstar.rb command [value]
11
+ USAGE = ' Usage: renstar.rb command [value]
12
12
 
13
13
  Informational Commands:
14
14
  info - Show current settings
15
15
  sensors - Show current Sensor reading
16
16
  runtimes - Show last 7 days of usage times
17
17
  alerts - Show alerts and their statuses
18
-
18
+
19
19
  Control Commands:
20
20
  Note: Temp values are integers. Device settings determine units.
21
21
  heat $TEMP - Heat to $TEMP
@@ -31,7 +31,7 @@ USAGE = ''' Usage: renstar.rb command [value]
31
31
  home - Set "Home"
32
32
  away - Set "Away"
33
33
 
34
- '''
34
+ '
35
35
 
36
36
  Options = Struct.new(:thermostat)
37
37
  args = Options.new
@@ -67,18 +67,21 @@ if args.thermostat
67
67
  puts "Using: #{thermo.location}"
68
68
  else
69
69
  thermos = Renstar::Thermostat.search
70
+ if thermos.empty?
71
+ puts 'No thermostats found'
72
+ exit 0
73
+ end
70
74
  thermos.each do |t|
71
75
  puts "Found: #{t.location} #{t.usn}"
72
76
  end
73
77
  thermo = thermos.first
74
78
  puts "Using: #{thermo.location} - #{thermo.usn}"
75
79
  end
76
- command = nil
77
- if ARGV.nil? || ARGV.empty?
78
- command = 'info'
79
- else
80
- command = ARGV
81
- end
80
+ command = if ARGV.nil? || ARGV.empty?
81
+ 'info'
82
+ else
83
+ ARGV
84
+ end
82
85
 
83
86
  response = thermo.send(*command)
84
87
  case response
@@ -7,14 +7,11 @@ module Renstar
7
7
  def initialize(raw_hash)
8
8
  @raw_hash = raw_hash
9
9
  raw_hash.each do |key, value|
10
- if key == 'ts'
11
- instance_variable_set("@#{key}", Time.at(value))
12
- else
13
- instance_variable_set("@#{key}", value)
14
- end
10
+ value = Time.at(value) if key == 'ts'
11
+ instance_variable_set("@#{key}", value)
15
12
 
16
13
  define_singleton_method(key) do
17
- return instance_variable_get("@#{key}")
14
+ instance_variable_get("@#{key}")
18
15
  end
19
16
  end
20
17
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ssdp'
4
+ require 'socket'
5
+
6
+ module Renstar
7
+ # Helper module for handling SSDP and IP details for discovery thermostats on
8
+ # the network
9
+ module Discovery
10
+ # Discovery timeout when searching for thermostats
11
+ SERVICE = 'venstar:thermostat:ecp'
12
+
13
+ private
14
+
15
+ def ips
16
+ Socket.ip_address_list.select do |ip|
17
+ ip.ipv4? && !ip.ipv4_loopback?
18
+ end
19
+ end
20
+
21
+ # do an SSDP search using the given IP from a found local interface
22
+ def ssdp_search(ip, timeout = 5)
23
+ puts "Searching subnet associated with #{ip.ip_address}"
24
+ ssdp = SSDP::Consumer.new({ bind: ip.ip_address })
25
+ thermos = ssdp.search(service: SERVICE, timeout: timeout)
26
+ end
27
+ end
28
+ end
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ssdp'
4
- require 'socket'
5
3
  require_relative 'api_client'
4
+ require_relative 'discovery'
6
5
 
7
6
  module Renstar
8
7
  # Thermostat object
@@ -11,13 +10,12 @@ module Renstar
11
10
  # Home/Away, and Off
12
11
  #
13
12
  class Thermostat
14
- SERVICE = 'venstar:thermostat:ecp'
15
13
  USN_REGEX = /^(\w+):(\w+)+:((?:[0-9a-fA-F]{2}:?)+):name:(.*):type:(.*)/
16
- DEFAULT_TIMEOUT = 3
17
14
 
18
15
  attr_reader :location, :usn, :cached_info
19
16
 
20
17
  include APIClient
18
+ extend Discovery
21
19
 
22
20
  def initialize(location, usn = nil)
23
21
  if location && usn
@@ -32,23 +30,16 @@ module Renstar
32
30
  @cached_info = info
33
31
  end
34
32
 
35
- def self.search(timeout = DEFAULT_TIMEOUT)
33
+ def self.search(timeout = 3)
36
34
  all_thermos = []
37
- ips = Socket.ip_address_list.select do |ip|
38
- ip.ipv4? &&
39
- !ip.ipv4_loopback?
40
- end
41
35
  ips.each do |ip|
42
- puts "Searching subnet associated with #{ip.ip_address}"
43
- ssdp = SSDP::Consumer.new({ bind: ip.ip_address })
44
- thermos = ssdp.search(service: SERVICE, timeout: timeout)
45
- thermos.each do |thermo|
46
- location = thermo[:params]['Location']
47
- usn = thermo[:params]['USN']
48
- all_thermos << Renstar::Thermostat.new(location, usn)
49
- end
36
+ all_thermos << ssdp_search(ip, timeout)
37
+ end
38
+ all_thermos.flatten.map do |thermo|
39
+ location = thermo[:params]['Location']
40
+ usn = thermo[:params]['USN']
41
+ Renstar::Thermostat.new(location, usn)
50
42
  end
51
- all_thermos
52
43
  end
53
44
 
54
45
  def update
@@ -113,11 +104,7 @@ module Renstar
113
104
  end
114
105
 
115
106
  def fan_toggle
116
- if @cached_info.fan == 1
117
- fan_off
118
- else
119
- fan_on
120
- end
107
+ @cached_info.fan == 1 ? fan_off : fan_on
121
108
  end
122
109
 
123
110
  def schedule_off
@@ -133,11 +120,7 @@ module Renstar
133
120
  end
134
121
 
135
122
  def schedule_toggle
136
- if @cached_info.schedule == 1
137
- schedule_off
138
- else
139
- schedule_on
140
- end
123
+ @cached_info.schedule == 1 ? schedule_off : schedule_on
141
124
  end
142
125
 
143
126
  def home
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Renstar
4
- VERSION = '0.4.2'
4
+ VERSION = '0.4.4'
5
5
  end
data/lib/renstar.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative 'renstar/version'
4
4
  require_relative 'renstar/thermostat'
5
5
  require_relative 'renstar/api_client'
6
+ require_relative 'renstar/discovery'
6
7
 
7
8
  module Renstar
8
9
  class Error < StandardError; end
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.2
4
+ version: 0.4.4
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-10-24 00:00:00.000000000 Z
11
+ date: 2023-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -68,6 +68,7 @@ files:
68
68
  - lib/renstar/api_client/control.rb
69
69
  - lib/renstar/api_client/query.rb
70
70
  - lib/renstar/api_client/settings.rb
71
+ - lib/renstar/discovery.rb
71
72
  - lib/renstar/thermostat.rb
72
73
  - lib/renstar/version.rb
73
74
  - renstar.gemspec