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 +5 -5
- data/domotics-core.gemspec +13 -14
- data/lib/domotics/core/element/button.rb +8 -17
- data/lib/domotics/core/element/motion_sensor.rb +3 -3
- data/lib/domotics/core/element/reed_switch.rb +3 -3
- data/lib/domotics/core/element/switch.rb +19 -9
- data/lib/domotics/core/version.rb +1 -1
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aa3e061dd51a3ebe28885793ab969d98f67df951c4fec5ff3e90bd48b1c76f89
|
4
|
+
data.tar.gz: 175278d956f8ccafda95bb89a371172181581c297f3fb9cad6eb9a7e4589027e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67c0ff46d5504c10d22278e300a57047fe45d23310890cb56c2153fd0c6f0e2144efabca02a5f37d7f6b022b45fd61ae387e5fac65cce5cc7443bc86740081f8
|
7
|
+
data.tar.gz: 12f3e5e769cb24e392f48c0c10afe6e9d962381294c74588e2372752b005b5f50498ded8a4ce0a6db82936abe9be61384f30a6bb145cb65bdb9226e33293e449
|
data/domotics-core.gemspec
CHANGED
@@ -1,21 +1,20 @@
|
|
1
|
-
|
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
|
3
|
+
require "domotics/core/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
11
|
-
spec.summary
|
12
|
-
spec.description
|
13
|
-
spec.homepage
|
14
|
-
spec.license
|
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
|
17
|
-
spec.executables
|
18
|
-
spec.test_files
|
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
|
-
@
|
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
|
-
|
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
|
-
|
19
|
+
@last_on = Time.now
|
20
20
|
when :off
|
21
21
|
case Time.now - (@last_on || Time.now)
|
22
|
-
when 0...0.
|
23
|
-
when 0.
|
24
|
-
when 0.3...1 then super :long_tap
|
25
|
-
|
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
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Domotics::Core
|
2
2
|
class Switch < Element
|
3
|
-
MINIMUM_LAG =
|
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
|
-
|
35
|
-
|
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
|
59
|
+
if @lag && @lag.alive?
|
51
60
|
@lag.kill
|
52
61
|
@lag = nil
|
53
62
|
end
|
54
|
-
raise ArgumentError unless
|
63
|
+
raise ArgumentError unless timer.is_a?(Integer) && (timer >= MINIMUM_LAG)
|
64
|
+
|
55
65
|
# Delayed action
|
56
|
-
@lag = Thread.new
|
66
|
+
@lag = Thread.new {
|
57
67
|
sleep timer
|
58
|
-
public_send action
|
59
|
-
|
68
|
+
block_given? ? (public_send(action) if block.call) : public_send(action)
|
69
|
+
}
|
60
70
|
end
|
61
71
|
rescue ArgumentError
|
62
72
|
nil
|
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.
|
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:
|
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
|
-
|
242
|
-
|
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:
|