home_assistant-ble 1.2.0 → 1.3.0
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
- data/lib/home_assistant/ble/version.rb +1 -1
- 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: 5032787cdddda273cb5b45a51d3d9f6c247f9077
|
4
|
+
data.tar.gz: 8f9da019ee04dda8dc59d5a2c30043887d84c8ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 209c4a747d75889eef7f78729214223f2b7049cf70b5a59ffc80f21889ff5b418dc9ce39c27a0e4540e1f0ff08e3f39f6cf69872187e7cee8e686d736ae385fd
|
7
|
+
data.tar.gz: 3ae70f258edbf1f31c70da3e5978f9b1f4b7f0f1a9f84bf779cf902c43aa1f8802e912ba64bd712de3c43388531f2a2a303cdf56cf97932fc62265cf89ef9c88
|
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!
|