nlhue 0.1.3 → 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: 06b6ea3762cfc73808dac91dd559a0b18d3d5179e4735b39b0158874c6e83506
4
- data.tar.gz: 5a32343e8b0a7a22e123c09edaf88cbaee1705db462d96b22a02280e0e6a777d
3
+ metadata.gz: 4c88ea67d9b9cc9f0b4f9871fdd0c914eda39ee51957c934cd8106b90ca3fac5
4
+ data.tar.gz: e5a62e8eb43c269bb78ba3231c88066d31b469838a49a0bcde8a784c61bd7276
5
5
  SHA512:
6
- metadata.gz: a795cc4d87efb3df87b855e24fd77bc77dfa1bc07f25ed1464b728a738d475bd2c627a2eb32b22f6886c43a72e043102b32ae2a0155aca2e8632c37ae8630faa
7
- data.tar.gz: f98467b14dc7849c29bdaf93a67701219cbe2eb153dbde915a74869162c80db06624dcca7c1017394875d0a496594b819514f66a23ed70341a6d053104b4978e
6
+ metadata.gz: bbad21227c522abd8c1fc6d4a8929747976e8dfe67e94ae93acd0c84f1a71991e41fe861be64b411693e4bb17adcddc5c17ad0e2530188fde3b8704197abcd1a
7
+ data.tar.gz: 9c1251cb375e6c3fcd6580dccec33d073aee51a3e7701b2680ceffaef92c8b17733e7489b6cad9ae56af63470e19989bc1e6d35e021faacd5d07913fbf4c27a7
data/lib/nlhue.rb CHANGED
@@ -1,30 +1,65 @@
1
1
  # Nitrogen Logic's Ruby interface library for the Philips Hue.
2
2
  # (C)2013 Mike Bourgeous
3
3
 
4
- # Dummy benchmarking method that may be overridden by library users.
5
- unless private_methods.include?(:bench)
6
- def bench label, *args, &block
7
- yield
8
- end
9
- end
4
+ module NLHue
5
+ module Log
6
+ @@log_block = nil
7
+ @@log_e_block = nil
8
+ @@bench_block = nil
10
9
 
11
- # Logging method that may be overridden by library users.
12
- unless private_methods.include?(:log)
13
- def log msg
14
- puts msg
15
- end
16
- end
10
+ # Pass a block that accepts a message to log, or pass nil to restore
11
+ # default logging.
12
+ def self.on_log(&block)
13
+ @@log_block = block
14
+ end
15
+
16
+ # Pass a block that accepts an exception and an optional message to log, or
17
+ # pass nil to restore default exception logging.
18
+ def self.on_log_e(&block)
19
+ @@log_e_block = block
20
+ end
21
+
22
+ # Pass a block to be called
23
+ def self.on_bench(&block)
24
+ @@bench_block = block
25
+ end
26
+
27
+ # Dummy benchmarking method that may be overridden by library users.
28
+ def bench(label, *args, &block)
29
+ if @@bench_block
30
+ @@bench_block.call(label, *args, &block)
31
+ else
32
+ yield
33
+ end
34
+ end
35
+
36
+ # Logging method that may be overridden by library users.
37
+ def log(msg)
38
+ if @@log_block
39
+ @@log_block.call(msg)
40
+ else
41
+ puts msg
42
+ end
43
+ end
44
+
45
+ # Exception logging method that may be overridden by library users using
46
+ # the on_log_e method.
47
+ def log_e(e, msg=nil)
48
+ if @@log_e_block
49
+ @@log_e_block.call(e, msg)
50
+ else
51
+ e ||= StandardError.new('No exception given to log')
52
+ if msg
53
+ log "#{msg}: #{e}", e.backtrace
54
+ else
55
+ log e, e.backtrace
56
+ end
57
+ end
58
+ end
59
+ end
17
60
 
18
- # Exception logging method that may be overridden by library users.
19
- unless private_methods.include?(:log_e)
20
- def log_e e, msg=nil
21
- e ||= StandardError.new('No exception given to log')
22
- if msg
23
- puts "#{msg}: #{e}", e.backtrace
24
- else
25
- puts e, e.backtrace
26
- end
27
- end
61
+ include Log
62
+ extend Log
28
63
  end
29
64
 
30
65
  require_relative 'nlhue/ssdp'
data/lib/nlhue/bridge.rb CHANGED
@@ -34,6 +34,9 @@ module NLHue
34
34
  # queued and sent one at a time to prevent overloading the bridge's
35
35
  # CPU.
36
36
  class Bridge
37
+ include NLHue::Log
38
+ extend NLHue::Log
39
+
37
40
  # Seconds to wait after an update round finishes before sending
38
41
  # more updates to lights and groups.
39
42
  RATE_LIMIT = 0.2
data/lib/nlhue/disco.rb CHANGED
@@ -11,6 +11,9 @@ module NLHue
11
11
  # Use #start_discovery and #stop_discovery for continuous bridge
12
12
  # discovery. Use #send_discovery to perform discovery only once.
13
13
  module Disco
14
+ include NLHue::Log
15
+ extend NLHue::Log
16
+
14
17
  # Number of times a bridge can be missing from discovery if not
15
18
  # subscribed (approx. 5*15=1.25min if interval is 15)
16
19
  MAX_BRIDGE_AGE = 5
@@ -238,7 +241,7 @@ module NLHue
238
241
  private
239
242
  # Calls each discovery callback with the given parameters.
240
243
  def self.notify_callbacks *args
241
- bench "Notify Hue disco callbacks: #{args[0].inspect}" do
244
+ NLHue.bench "Notify Hue disco callbacks: #{args[0].inspect}" do
242
245
  @@disco_callbacks.each do |cb|
243
246
  begin
244
247
  cb.call *args
@@ -313,7 +316,7 @@ module NLHue
313
316
  # callbacks. Called when the timer set by #reset_disco_timer
314
317
  # expires.
315
318
  def self.update_bridges bridges
316
- bench 'update_bridges' do
319
+ NLHue.bench 'update_bridges' do
317
320
  @@bridges.select! do |k, br|
318
321
  age_limit = br[:bridge].subscribed? ? MAX_SUBSCRIBED_AGE : MAX_BRIDGE_AGE
319
322
 
@@ -8,6 +8,9 @@ require 'em/protocols/httpclient'
8
8
 
9
9
  module NLHue
10
10
  class RequestQueue
11
+ include NLHue::Log
12
+ extend NLHue::Log
13
+
11
14
  attr_reader :host
12
15
 
13
16
  # Initializes a request queue with the given host, default
data/lib/nlhue/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module NLHue
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nlhue
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
  - Mike Bourgeous
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-05 00:00:00.000000000 Z
11
+ date: 2021-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler