domotics-core 0.2.7 → 0.2.8

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
- SHA1:
3
- metadata.gz: 3c82136cdfecddb9568a2d83694c21a2e3a3b587
4
- data.tar.gz: 0501d81331a6de29327ce59d42fd4030bb840607
2
+ SHA256:
3
+ metadata.gz: aa3e061dd51a3ebe28885793ab969d98f67df951c4fec5ff3e90bd48b1c76f89
4
+ data.tar.gz: 175278d956f8ccafda95bb89a371172181581c297f3fb9cad6eb9a7e4589027e
5
5
  SHA512:
6
- metadata.gz: cb5bb04aaf28fe8d6ff4de7e8abeba8691524f78885325db072671f58f76b0466c21494620cab2a4260c51df6cd15d14a886f74846d80e80174cd1edbe5c6bf0
7
- data.tar.gz: bbf33de38b9e412374e2894b8c363974d39074abb1c1f2ed1ba4767a569f0e9847a8ede9023fcc52234a4bdb1e809c3aec636cbb3e763f7fddc1e9c531a933a7
6
+ metadata.gz: 67c0ff46d5504c10d22278e300a57047fe45d23310890cb56c2153fd0c6f0e2144efabca02a5f37d7f6b022b45fd61ae387e5fac65cce5cc7443bc86740081f8
7
+ data.tar.gz: 12f3e5e769cb24e392f48c0c10afe6e9d962381294c74588e2372752b005b5f50498ded8a4ce0a6db82936abe9be61384f30a6bb145cb65bdb9226e33293e449
@@ -1,21 +1,20 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'domotics/core/version'
3
+ require "domotics/core/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "domotics-core"
8
- spec.version = Domotics::Core::VERSION
9
- spec.authors = ["goredar"]
10
- spec.email = ["info@goredar.it"]
11
- spec.summary = %q{Home automation system.}
12
- spec.description = %q{Main core elements}
13
- spec.homepage = "https://goredar.it"
14
- spec.license = "MIT"
6
+ spec.name = "domotics-core"
7
+ spec.version = Domotics::Core::VERSION
8
+ spec.authors = ["goredar"]
9
+ spec.email = ["info@goredar.it"]
10
+ spec.summary = "Home automation system."
11
+ spec.description = "Main core elements"
12
+ spec.homepage = "https://goredar.it"
13
+ spec.license = "MIT"
15
14
 
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
18
  spec.require_paths = ["lib"]
20
19
 
21
20
  spec.add_runtime_dependency "domotics-arduino"
@@ -3,35 +3,26 @@ module Domotics::Core
3
3
  def initialize(args = {})
4
4
  @type = args[:type] || :button
5
5
  @touch = args[:touch]
6
- @taped = true
7
- #@tap_lock = Mutex.new
6
+ @last_on = nil
8
7
  args[:driver] = @touch ? "DigitalSensor" : "NOSensor"
9
8
  load_driver args
10
9
  super
11
10
  end
12
- def set_state(*args)
11
+
12
+ def set_state(*_args)
13
13
  nil
14
14
  end
15
15
 
16
16
  def state_changed(value)
17
17
  case value
18
18
  when :on
19
- (@last_on = Time.now; @taped = false) if @taped
19
+ @last_on = Time.now
20
20
  when :off
21
21
  case Time.now - (@last_on || Time.now)
22
- when 0...0.01 then return # debounce
23
- when 0.01...0.3 then super :tap; @taped = true
24
- when 0.3...1 then super :long_tap; @taped = true
25
- #@tap_lock.synchronize do
26
- # if @tap and @tap.alive?
27
- # @tap.kill
28
- # @tap = nil
29
- # super :double_tap
30
- # else
31
- # @tap = Thread.new { sleep 0.25; super :tap }
32
- # end
33
- #end
34
- else super :long_tap_x2; @taped = true
22
+ when 0...0.03 then nil # debounce
23
+ when 0.03...0.3 then super :tap
24
+ when 0.3...1 then super :long_tap
25
+ when 1...2 then super :long_tap_x2
35
26
  end
36
27
  end
37
28
  end
@@ -6,9 +6,9 @@ module Domotics::Core
6
6
  load_driver args
7
7
  super
8
8
  end
9
- #def to_hls(state)
10
- # super == :on ? :move : :no_move
11
- #end
9
+ def to_hls(state)
10
+ super == :on ? :move : :no_move
11
+ end
12
12
  def set_state(*args)
13
13
  nil
14
14
  end
@@ -6,9 +6,9 @@ module Domotics::Core
6
6
  load_driver args
7
7
  super
8
8
  end
9
- #def to_hls(state)
10
- # super == :on ? :open : :close
11
- #end
9
+ def to_hls(state)
10
+ super == :on ? :open : :close
11
+ end
12
12
  def set_state(*args)
13
13
  nil
14
14
  end
@@ -1,6 +1,6 @@
1
1
  module Domotics::Core
2
2
  class Switch < Element
3
- MINIMUM_LAG = 1
3
+ MINIMUM_LAG = 0
4
4
  def initialize(args = {})
5
5
  @type = args[:type] || :switch
6
6
  @lag = nil
@@ -11,52 +11,62 @@ module Domotics::Core
11
11
  super
12
12
  @initialized = true
13
13
  end
14
+
14
15
  def set_state(value)
15
16
  @initialized ? (super unless state == value) : super
16
17
  end
18
+
17
19
  def on(timer = nil)
18
20
  set_state :on
19
21
  lag(:off, timer)
20
22
  end
23
+
21
24
  def on?
22
25
  state == :on
23
26
  end
27
+
24
28
  def delay_on(timer)
25
29
  lag(:on, timer)
26
30
  end
31
+
27
32
  def off(timer = nil)
28
33
  set_state :off
29
34
  lag(:on, timer)
30
35
  end
36
+
31
37
  def off?
32
38
  state == :off
33
39
  end
34
- def delay_off(timer)
35
- lag(:off, timer)
40
+
41
+ def delay_off(timer, &block)
42
+ lag(:off, timer, &block)
36
43
  end
44
+
37
45
  def toggle(timer = nil)
38
46
  set_state state == :off ? :on : :off
39
47
  lag(:toggle, timer)
40
48
  end
49
+
41
50
  def delay_toggle(timer)
42
51
  lag(:toggle, timer)
43
52
  end
44
53
 
45
54
  private
46
55
 
47
- def lag(action = nil, timer = nil)
56
+ def lag(action = nil, timer = nil, &block)
48
57
  # Kill previous action -> out of date
49
58
  @lag_lock.synchronize do
50
- if @lag and @lag.alive?
59
+ if @lag && @lag.alive?
51
60
  @lag.kill
52
61
  @lag = nil
53
62
  end
54
- raise ArgumentError unless (timer.is_a?(Integer) and timer >= MINIMUM_LAG)
63
+ raise ArgumentError unless timer.is_a?(Integer) && (timer >= MINIMUM_LAG)
64
+
55
65
  # Delayed action
56
- @lag = Thread.new do
66
+ @lag = Thread.new {
57
67
  sleep timer
58
- public_send action
59
- end
68
+ block_given? ? (public_send(action) if block.call) : public_send(action)
69
+ }
60
70
  end
61
71
  rescue ArgumentError
62
72
  nil
@@ -1,6 +1,6 @@
1
1
  module Domotics
2
2
  module Core
3
- VERSION = "0.2.7"
3
+ VERSION = "0.2.8"
4
4
  end
5
5
  end
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domotics-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - goredar
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-07 00:00:00.000000000 Z
11
+ date: 2020-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: domotics-arduino
@@ -223,7 +223,7 @@ homepage: https://goredar.it
223
223
  licenses:
224
224
  - MIT
225
225
  metadata: {}
226
- post_install_message:
226
+ post_install_message:
227
227
  rdoc_options: []
228
228
  require_paths:
229
229
  - lib
@@ -238,9 +238,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
238
  - !ruby/object:Gem::Version
239
239
  version: '0'
240
240
  requirements: []
241
- rubyforge_project:
242
- rubygems_version: 2.2.2
243
- signing_key:
241
+ rubygems_version: 3.1.4
242
+ signing_key:
244
243
  specification_version: 4
245
244
  summary: Home automation system.
246
245
  test_files: