rzwaveway 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rzwaveway/logger.rb +7 -0
- data/lib/rzwaveway/version.rb +1 -1
- data/lib/rzwaveway/zwave_device.rb +3 -2
- data/lib/rzwaveway/zway.rb +21 -21
- data/lib/rzwaveway.rb +2 -1
- data/spec/spec_helper.rb +0 -8
- data/spec/zway_spec.rb +1 -1
- metadata +2 -1
data/lib/rzwaveway/version.rb
CHANGED
@@ -4,6 +4,7 @@ module RZWaveWay
|
|
4
4
|
class ZWaveDevice
|
5
5
|
include CommandClass
|
6
6
|
include CommandClasses
|
7
|
+
include Logger
|
7
8
|
|
8
9
|
attr_reader :name
|
9
10
|
attr_reader :id
|
@@ -13,7 +14,7 @@ module RZWaveWay
|
|
13
14
|
def initialize(id, data)
|
14
15
|
@id = id
|
15
16
|
initialize_from data
|
16
|
-
|
17
|
+
log.info "Created ZWaveDevice with name='#{name}' (id='#{id}')"
|
17
18
|
end
|
18
19
|
|
19
20
|
def contacts_controller_periodically?
|
@@ -52,7 +53,7 @@ module RZWaveWay
|
|
52
53
|
event = @command_classes[cc].process(values)
|
53
54
|
events << event if event
|
54
55
|
else
|
55
|
-
|
56
|
+
log.warn "Could not find command class: '#{cc}'"
|
56
57
|
end
|
57
58
|
end
|
58
59
|
process_device_data(updates, events)
|
data/lib/rzwaveway/zway.rb
CHANGED
@@ -10,17 +10,10 @@ module RZWaveWay
|
|
10
10
|
include Log4r
|
11
11
|
|
12
12
|
attr_reader :devices
|
13
|
+
attr_reader :log
|
13
14
|
|
14
15
|
def initialize
|
15
|
-
|
16
|
-
formatter = PatternFormatter.new(:pattern => "[%l] %d - %m")
|
17
|
-
outputter = Outputter.stdout
|
18
|
-
outputter.formatter = formatter
|
19
|
-
outputter.level = Log4r::INFO
|
20
|
-
file_outputter = RollingFileOutputter.new('file', filename: 'rzwaveway.log', maxsize: 1048576, trunc: 86400)
|
21
|
-
file_outputter.formatter = formatter
|
22
|
-
file_outputter.level = Log4r::DEBUG
|
23
|
-
$log.outputters = [Outputter.stdout, file_outputter]
|
16
|
+
@log = default_logger
|
24
17
|
end
|
25
18
|
|
26
19
|
def execute(device_id, command_class, command_class_function, argument = nil)
|
@@ -37,10 +30,13 @@ module RZWaveWay
|
|
37
30
|
clazz.new(device)
|
38
31
|
end
|
39
32
|
|
40
|
-
def setup(
|
33
|
+
def setup(options, *adapter_params)
|
34
|
+
hostname = options[:hostname] || '127.0.0.1'
|
35
|
+
port = options[:port] || 8083
|
41
36
|
adapter_params = :httpclient if adapter_params.compact.empty?
|
42
|
-
@base_uri="http://#{hostname}
|
37
|
+
@base_uri="http://#{hostname}:#{port}"
|
43
38
|
@connection = Faraday.new {|faraday| faraday.adapter *adapter_params}
|
39
|
+
@log = options[:logger] if options.has_key? :logger
|
44
40
|
end
|
45
41
|
|
46
42
|
def start
|
@@ -54,7 +50,7 @@ module RZWaveWay
|
|
54
50
|
break
|
55
51
|
else
|
56
52
|
sleep 1.0
|
57
|
-
|
53
|
+
log.warn 'No devices found at start-up, retrying'
|
58
54
|
end
|
59
55
|
end
|
60
56
|
end
|
@@ -103,13 +99,17 @@ module RZWaveWay
|
|
103
99
|
end
|
104
100
|
end
|
105
101
|
|
102
|
+
def default_logger
|
103
|
+
Log4r::Logger.new 'RZWaveWay'
|
104
|
+
end
|
105
|
+
|
106
106
|
def deliver_to_handlers events
|
107
107
|
events.each do |event|
|
108
108
|
handler = @event_handlers[event.class]
|
109
109
|
if handler
|
110
110
|
handler.call(event)
|
111
111
|
else
|
112
|
-
|
112
|
+
log.warn "No event handler for #{event.class}"
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
@@ -122,7 +122,7 @@ module RZWaveWay
|
|
122
122
|
device_events = @devices[id].process updates
|
123
123
|
events += device_events unless device_events.empty?
|
124
124
|
else
|
125
|
-
|
125
|
+
log.warn "Could not find device with id '#{id}'"
|
126
126
|
end
|
127
127
|
end
|
128
128
|
events
|
@@ -137,7 +137,7 @@ module RZWaveWay
|
|
137
137
|
updates_per_device[device_id] = {} unless(updates_per_device.has_key?(device_id))
|
138
138
|
updates_per_device[device_id][match_data.post_match] = value
|
139
139
|
else
|
140
|
-
|
140
|
+
log.debug "No device group match for key='#{key}'"
|
141
141
|
end
|
142
142
|
end
|
143
143
|
updates_per_device
|
@@ -152,10 +152,10 @@ module RZWaveWay
|
|
152
152
|
results = JSON.parse response.body
|
153
153
|
@update_time = results.delete('updateTime')
|
154
154
|
else
|
155
|
-
|
155
|
+
log.error(response.reason)
|
156
156
|
end
|
157
157
|
rescue StandardError => e
|
158
|
-
|
158
|
+
log.error("Failed to communicate with ZWay HTTP server: #{e}")
|
159
159
|
end
|
160
160
|
results
|
161
161
|
end
|
@@ -199,12 +199,12 @@ module RZWaveWay
|
|
199
199
|
uri = URI.encode(@base_uri + RUN_BASE_PATH + command_path, '[]')
|
200
200
|
response = @connection.get(uri)
|
201
201
|
unless response.success?
|
202
|
-
|
203
|
-
|
202
|
+
log.error(response.status)
|
203
|
+
log.error(response.body)
|
204
204
|
end
|
205
205
|
rescue StandardError => e
|
206
|
-
|
207
|
-
|
206
|
+
log.error("Failed to communicate with ZWay HTTP server: #{e}")
|
207
|
+
log.error(e.backtrace)
|
208
208
|
end
|
209
209
|
end
|
210
210
|
end
|
data/lib/rzwaveway.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative 'rzwaveway/command_classes'
|
2
2
|
require_relative 'rzwaveway/events'
|
3
|
+
require_relative 'rzwaveway/logger'
|
3
4
|
require_relative 'rzwaveway/zwave_device'
|
4
5
|
require_relative 'rzwaveway/zway'
|
5
|
-
require_relative 'rzwaveway/extensions'
|
6
|
+
require_relative 'rzwaveway/extensions'
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'rzwaveway'
|
2
|
-
require 'log4r'
|
3
2
|
require 'securerandom'
|
4
3
|
|
5
4
|
module SpecHelpers
|
@@ -28,10 +27,3 @@ end
|
|
28
27
|
RSpec.configure do |c|
|
29
28
|
c.include SpecHelpers
|
30
29
|
end
|
31
|
-
|
32
|
-
$log = Log4r::Logger.new 'RZWaveWay'
|
33
|
-
# formatter = Log4r::PatternFormatter.new(:pattern => "[%l] %d - %m")
|
34
|
-
# outputter = Log4r::Outputter.stdout
|
35
|
-
# outputter.formatter = formatter
|
36
|
-
# outputter.level = Log4r::DEBUG
|
37
|
-
# $log.outputters = [Log4r::Outputter.stdout]
|
data/spec/zway_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rzwaveway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/rzwaveway/extensions.rb
|
114
114
|
- lib/rzwaveway/extensions/fibaro_smoke_sensor.rb
|
115
115
|
- lib/rzwaveway/extensions/ssa_siren_strobe_alarm.rb
|
116
|
+
- lib/rzwaveway/logger.rb
|
116
117
|
- lib/rzwaveway/version.rb
|
117
118
|
- lib/rzwaveway/zwave_device.rb
|
118
119
|
- lib/rzwaveway/zway.rb
|