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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41ac6003838b2dbd9aa2dd47f0e0b6ae37f5e582
4
- data.tar.gz: 9d9d85e7ff4f5e0acfce610409b311d063fd94fd
3
+ metadata.gz: 5032787cdddda273cb5b45a51d3d9f6c247f9077
4
+ data.tar.gz: 8f9da019ee04dda8dc59d5a2c30043887d84c8ae
5
5
  SHA512:
6
- metadata.gz: 5932ff84754b1e518886b3ae12d0a34fc57fe24c1d8c5469519a62a81e1e3e931a21e2c386852adfadec807b7425dfada266ca1d1b3b7a360d3171a140373243
7
- data.tar.gz: '089d9ab7c88ae419daea1fc3cfeff26ab2097d7b8e870c63ae49c7706d5b3dbd1d4988ddfc92deb5ac28834473f32b9c3ef549e0392fc9dbeaefd09a7a1b6b81'
6
+ metadata.gz: 209c4a747d75889eef7f78729214223f2b7049cf70b5a59ffc80f21889ff5b418dc9ce39c27a0e4540e1f0ff08e3f39f6cf69872187e7cee8e686d736ae385fd
7
+ data.tar.gz: 3ae70f258edbf1f31c70da3e5978f9b1f4b7f0f1a9f84bf779cf902c43aa1f8802e912ba64bd712de3c43388531f2a2a303cdf56cf97932fc62265cf89ef9c88
@@ -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!
@@ -1,5 +1,5 @@
1
1
  module HomeAssistant
2
2
  module Ble
3
- VERSION = '1.2.0'.freeze
3
+ VERSION = '1.3.0'.freeze
4
4
  end
5
5
  end
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
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grégoire Seux