home_assistant-ble 1.4.0.pre.alpha.pre.50 → 1.4.2

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: 622bc1ec8d5545186dae5bf39994e74d9cbd5777
4
- data.tar.gz: ab020ca5c8832f2a67b06682af3a9e6a229c43ac
3
+ metadata.gz: df137ae166f962112cbaf769795065e6ef454c78
4
+ data.tar.gz: e5837bc320fd2bb0bab1514440d2279025c10d5e
5
5
  SHA512:
6
- metadata.gz: ead1203b97722a6cb71cad66062590230b8446e0bdc5bef0ebe62904cc379c050d5bc5a9988880dc2a73eb3904a9783e14be1b1d2be63b9ed5d94ea464ce3fa9
7
- data.tar.gz: d929dee60d3a1d7303c82c1a6fbbc941a91ff1ac6b0ee90828cb35ec66ac96a27e2d3e5168cc5f3ec361415b4dd7bf0bf8b8ea3c2140975027e241a0d641fa83
6
+ metadata.gz: 7c86d06ff34769b00c7d2c27c8b5f4462e3b11f11a4454a956a955ff6c899a122b7baa9fd130cc070a937a80e8174dce1618c9a1d38e1debd27ef8f7e1b0d4c0
7
+ data.tar.gz: e2cc1991f47d847c9da8090ea84487dbbb4ca6833289a68c91167bcb532b9a85dcc8dc8ff56044d0234b27e42ea773223a5b88eba8516437b713f7c17448d378
data/README.md CHANGED
@@ -41,7 +41,8 @@ sudo setcap 'cap_net_raw,cap_net_admin+eip' `readlink -f \`which ruby\``
41
41
  interval: 30 # in seconds, interval between device scan. Defaults to 30
42
42
  grace_period: 60 # in seconds, delay before considering a device has disappeared. Defaults to 60
43
43
  home_assistant_url: http://localhost:8123 # url to contact home-assistant. Defaults to http://localhost:8123
44
- home_assistant_password: xxxxx # non mandatory password to authenticate to home-assistant api. Default is nil
44
+ home_assistant_token: token # Long lived access token if you're using the `homeassistant` http auth type.
45
+ home_assistant_password: xxxxx # non mandatory password to authenticate to home-assistant api. Default is nil. If `home_assistant_token` is provided this setting has no effect
45
46
  home_assistant_devices: # devices whose activity will be sent to home-assistant. Default is empty (no tracked devices)
46
47
  F0:5C:F4:EA:BF:C8: nut1 # [macaddress]: [identifier for home-assistant]
47
48
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/ruby2.3
2
2
 
3
3
  require 'home_assistant/ble'
4
4
  require 'yaml'
@@ -11,17 +11,15 @@ $stderr.sync = true
11
11
 
12
12
  def shut_down
13
13
  @detector.clean_all_devices
14
- $stdout.puts 'Quitting...'
14
+ $stdout.puts 'Quitting'
15
15
  end
16
16
 
17
17
  Signal.trap('INT') do
18
- $stdout.puts 'Received SIGINT.'
19
18
  shut_down
20
19
  exit
21
20
  end
22
21
 
23
22
  Signal.trap('TERM') do
24
- $stdout.puts 'Received SIGTERM.'
25
23
  shut_down
26
24
  exit
27
25
  end
@@ -36,10 +34,4 @@ end
36
34
 
37
35
  @detector = HomeAssistant::Ble::Detector.new(config)
38
36
 
39
- begin
40
- @detector.run
41
- rescue ScriptError
42
- # If no BLE interface is available clean up and exit
43
- $stdout.puts 'No Bluetooth interfaces available.'
44
- shut_down
45
- end
37
+ @detector.run
@@ -2,6 +2,7 @@ interval: 30 # in seconds
2
2
  grace_period: 60 # in seconds
3
3
  home_assistant_url: http://localhost:8123
4
4
  # home_assistant_password: xxxxx
5
+ # home_assistant_token: xxxxx
5
6
  home_assistant_devices:
6
7
  F0:5C:F4:EA:BE:C1: a_device
7
8
  home_assistant_devices_file: /var/lib/hass/known_devices.yaml
@@ -39,6 +39,10 @@ module HomeAssistant
39
39
  config['home_assistant_password']
40
40
  end
41
41
 
42
+ def home_assistant_token
43
+ config['home_assistant_token']
44
+ end
45
+
42
46
  def home_assistant_devices
43
47
  devices = {}
44
48
  if config['home_assistant_devices_file']
@@ -47,7 +51,7 @@ module HomeAssistant
47
51
  next unless conf['track']
48
52
  mac = conf['mac'].gsub(/^(ble_|bt_)/i, '').upcase
49
53
  conf['dev_id'] = name
50
- devices[mac] = conf.select { |k, _v| %w(dev_id mac name).include? k }
54
+ devices[mac] = conf.select { |k, _v| %w(dev_id mac).include? k }
51
55
  debug "Adding #{mac} (#{conf['name']}) found in known_devices.yaml"
52
56
  end
53
57
  end
@@ -120,7 +124,14 @@ module HomeAssistant
120
124
  uri = URI.join(home_assistant_url, '/api/services/device_tracker/see')
121
125
  request = Net::HTTP::Post.new(uri)
122
126
  request.content_type = 'application/json'
123
- request['X-Ha-Access'] = home_assistant_password if home_assistant_password
127
+ request['Accept-Encoding'] = 'plain'
128
+
129
+ if home_assistant_token
130
+ request['Authorization'] = "Bearer #{home_assistant_token}"
131
+ elsif home_assistant_password
132
+ request['X-Ha-Access'] = home_assistant_password
133
+ end
134
+
124
135
  request.body = ha_conf.to_json
125
136
  req_options = { use_ssl: uri.scheme == 'https' }
126
137
 
@@ -1,5 +1,5 @@
1
1
  module HomeAssistant
2
2
  module Ble
3
- VERSION = '1.4.0'.freeze
3
+ VERSION = '1.4.2'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: home_assistant-ble
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0.pre.alpha.pre.50
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grégoire Seux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-02 00:00:00.000000000 Z
11
+ date: 2019-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -129,12 +129,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  requirements:
132
- - - ">"
132
+ - - ">="
133
133
  - !ruby/object:Gem::Version
134
- version: 1.3.1
134
+ version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.4.5
137
+ rubygems_version: 2.5.2.1
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: Companion app for home-assistant sending event about BLE devices