home_assistant-ble 1.3.0 → 1.3.1

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: 5032787cdddda273cb5b45a51d3d9f6c247f9077
4
- data.tar.gz: 8f9da019ee04dda8dc59d5a2c30043887d84c8ae
3
+ metadata.gz: a23b76747cc7c5e4722adbbf6fe881e5ff2b18d1
4
+ data.tar.gz: 2113ebdd0d8b275ac9d7340718b80291bc4b191b
5
5
  SHA512:
6
- metadata.gz: 209c4a747d75889eef7f78729214223f2b7049cf70b5a59ffc80f21889ff5b418dc9ce39c27a0e4540e1f0ff08e3f39f6cf69872187e7cee8e686d736ae385fd
7
- data.tar.gz: 3ae70f258edbf1f31c70da3e5978f9b1f4b7f0f1a9f84bf779cf902c43aa1f8802e912ba64bd712de3c43388531f2a2a303cdf56cf97932fc62265cf89ef9c88
6
+ metadata.gz: aa42612f3d48e2e2f9cbfccb221c25904f34163bdd78b087594357e7536c5f5cab92e0b5438c7f950f60f6174b46887fae010ff8399dbba8ca1c95816ad9fe5c
7
+ data.tar.gz: f59361122fa9aea39451dd38aabff74c0bb222f0929a7dcee4aca97fd24b41472d85ad6ac8ba80e374d2f6c36ee153000c16e9a7ea821b9e97ed6e615806a9fb
data/README.md CHANGED
@@ -9,8 +9,11 @@ Since HA does not cope well with bluetooth device tracking (https://home-assista
9
9
 
10
10
  ## Installation
11
11
 
12
+ For raspbian install required packages:
12
13
 
13
- $ `gem install home_assistant-ble`
14
+ $ sudo apt-get install ruby-dev libcap-dev
15
+
16
+ $ gem install home_assistant-ble
14
17
 
15
18
  ## Usage
16
19
 
@@ -5,6 +5,7 @@ require 'net/http'
5
5
  require 'uri'
6
6
  require 'json'
7
7
  require 'cap2'
8
+ require 'digest/md5'
8
9
 
9
10
  module HomeAssistant
10
11
  module Ble
@@ -44,12 +45,19 @@ module HomeAssistant
44
45
  YAML.load_file(config['home_assistant_devices_file']).each do |name, conf|
45
46
  next unless conf['mac'] =~ /^(ble_|bt_)/i
46
47
  next unless conf['track']
47
- mac = conf['mac'].gsub(/^(ble_|bt_)/i, '').upcase
48
- devices[mac] = name
48
+ mac = conf.delete('mac').gsub(/^(ble_|bt_)/i, '').upcase
49
+ conf['name'] = name # erase name with HA id
50
+ devices[mac] = conf
49
51
  debug "Adding #{mac} (#{name}) found in known_devices.yaml"
50
52
  end
51
53
  end
52
- devices.merge!(config['home_assistant_devices']) if config['home_assistant_devices']
54
+ if config['home_assistant_devices']
55
+ config['home_assistant_devices'].each do |mac, name|
56
+ devices[mac] = Mash.new(name: name)
57
+ end
58
+ end
59
+
60
+ devices
53
61
  end
54
62
 
55
63
  def run
@@ -98,12 +106,23 @@ module HomeAssistant
98
106
  end
99
107
  end
100
108
 
101
- def update_home_assistant(ha_name, state)
109
+ def state_update(ha_conf, state)
110
+ attributes = {}
111
+ attributes['entity_picture'] = ha_conf['picture']
112
+ if ha_conf['gravatar']
113
+ hash = Digest::MD5.hexdigest(ha_conf['gravatar'].downcase)
114
+ attributes['entity_picture'] = "https://www.gravatar.com/avatar/#{hash}"
115
+ end
116
+ JSON.dump('state' => state, 'attributes' => attributes)
117
+ end
118
+
119
+ def update_home_assistant(ha_conf, state)
120
+ ha_name = ha_conf['name']
102
121
  uri = URI.join(home_assistant_url, "api/states/device_tracker.#{ha_name}")
103
122
  request = Net::HTTP::Post.new(uri)
104
123
  request.content_type = 'application/json'
105
124
  request['X-Ha-Access'] = home_assistant_password if home_assistant_password
106
- request.body = JSON.dump('state' => state)
125
+ request.body = state_update(ha_conf, state)
107
126
  req_options = { use_ssl: uri.scheme == 'https' }
108
127
 
109
128
  response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
@@ -1,5 +1,5 @@
1
1
  module HomeAssistant
2
2
  module Ble
3
- VERSION = '1.3.0'.freeze
3
+ VERSION = '1.3.1'.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.3.0
4
+ version: 1.3.1
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-03-29 00:00:00.000000000 Z
11
+ date: 2017-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler