home_assistant-ble 1.2.0.pre.alpha.pre.25 → 1.2.0.pre.alpha.pre.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/home_assistant/ble.rb +18 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e962366e242a811c1629e3d1b6b31f8cf091df6f
|
4
|
+
data.tar.gz: 2d4f69d0681cfecf051518f5ee7e67b7946a699a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a354881a9191742f2a63da85031fb8e50139d6bafb46ad370fa67d5a10854257475013dff7987f94346be9d853b234741a66451869a2c04c6df6f575f559258e
|
7
|
+
data.tar.gz: 460e4979e32733a61a6d9321c15e9e91c781482c8de60850bd309f130a3b78fd6dee6078653548786b951f00c5b7d2b33bf03af6e5be4861c3ef484ca096c190
|
data/lib/home_assistant/ble.rb
CHANGED
@@ -16,6 +16,10 @@ module HomeAssistant
|
|
16
16
|
@known_devices = {}
|
17
17
|
end
|
18
18
|
|
19
|
+
def discovery_time
|
20
|
+
config['discovery_time'] || 60
|
21
|
+
end
|
22
|
+
|
19
23
|
# polling interval
|
20
24
|
def interval
|
21
25
|
config['interval'] || 30
|
@@ -50,9 +54,9 @@ module HomeAssistant
|
|
50
54
|
|
51
55
|
def run
|
52
56
|
loop do
|
53
|
-
|
57
|
+
discover
|
58
|
+
detect_new_devices
|
54
59
|
clean_devices
|
55
|
-
release_adapter
|
56
60
|
debug "Will sleep #{interval}s before relisting devices"
|
57
61
|
sleep interval
|
58
62
|
end
|
@@ -72,7 +76,7 @@ module HomeAssistant
|
|
72
76
|
puts message
|
73
77
|
end
|
74
78
|
|
75
|
-
def
|
79
|
+
def detect_new_devices
|
76
80
|
adapter.devices.each do |name|
|
77
81
|
unless known_devices.key?(name)
|
78
82
|
log "Just discovered #{name}"
|
@@ -122,18 +126,20 @@ module HomeAssistant
|
|
122
126
|
iface = BLE::Adapter.list.first
|
123
127
|
debug "Selecting #{iface} to listen for bluetooth events"
|
124
128
|
raise 'Unable to find a bluetooth device' unless iface
|
125
|
-
BLE::Adapter.new(iface)
|
126
|
-
debug 'Activating discovery'
|
127
|
-
a.start_discovery
|
128
|
-
debug 'Sleeping a bit to discover devices'
|
129
|
-
sleep 20
|
130
|
-
a.stop_discovery
|
131
|
-
end
|
129
|
+
BLE::Adapter.new(iface)
|
132
130
|
end
|
133
131
|
end
|
134
132
|
|
135
|
-
def
|
136
|
-
|
133
|
+
def discover
|
134
|
+
debug 'Cleaning old devices'
|
135
|
+
adapter.devices.dup.each do |d|
|
136
|
+
adapter[d].remove
|
137
|
+
end
|
138
|
+
debug 'Activating discovery'
|
139
|
+
adapter.start_discovery
|
140
|
+
debug 'Sleeping a bit to discover devices'
|
141
|
+
sleep discovery_time
|
142
|
+
adapter.stop_discovery
|
137
143
|
end
|
138
144
|
|
139
145
|
def ensure_rights!
|