home_assistant-ble 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/lib/home_assistant/ble.rb +24 -5
- data/lib/home_assistant/ble/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a23b76747cc7c5e4722adbbf6fe881e5ff2b18d1
|
4
|
+
data.tar.gz: 2113ebdd0d8b275ac9d7340718b80291bc4b191b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
$
|
14
|
+
$ sudo apt-get install ruby-dev libcap-dev
|
15
|
+
|
16
|
+
$ gem install home_assistant-ble
|
14
17
|
|
15
18
|
## Usage
|
16
19
|
|
data/lib/home_assistant/ble.rb
CHANGED
@@ -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
|
48
|
-
|
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
|
-
|
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
|
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 =
|
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|
|
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.
|
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-
|
11
|
+
date: 2017-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|