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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/home_assistant/ble.rb +18 -12
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c18742553e5d1415a026d205fa5aaa1bbd21944b
4
- data.tar.gz: 024c171360e06c15fe0c41a7a7451b6896cd6542
3
+ metadata.gz: e962366e242a811c1629e3d1b6b31f8cf091df6f
4
+ data.tar.gz: 2d4f69d0681cfecf051518f5ee7e67b7946a699a
5
5
  SHA512:
6
- metadata.gz: c6aa82f4939aa225a3cb5c1b71a93cd2bf5bdc5b69f437cf51d572c12ea232a203fcd29b6d5fffc505e78eba532fa5d5b402faedb7f18e6c337004cfe137e315
7
- data.tar.gz: d164b86fd4481664e68ec265005cb0b0e767bd179fdd05115944469ab6a4f09b727a01c1188a52a6b8ed0f63f1ca1a15112545059bc886155083d76d32046b46
6
+ metadata.gz: a354881a9191742f2a63da85031fb8e50139d6bafb46ad370fa67d5a10854257475013dff7987f94346be9d853b234741a66451869a2c04c6df6f575f559258e
7
+ data.tar.gz: 460e4979e32733a61a6d9321c15e9e91c781482c8de60850bd309f130a3b78fd6dee6078653548786b951f00c5b7d2b33bf03af6e5be4861c3ef484ca096c190
@@ -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
- detect_devices
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 detect_devices
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).tap do |a|
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 release_adapter
136
- @adapter = nil
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!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: home_assistant-ble
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.pre.alpha.pre.25
4
+ version: 1.2.0.pre.alpha.pre.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grégoire Seux