home_assistant-ble 1.4.0.pre.alpha.pre.32 → 1.4.0.pre.alpha.pre.37

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 +12 -21
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2d40822bc4dd54c92cc3dd735499eeaaf6251c3
4
- data.tar.gz: ea08ebd4d2cf0b8586240ae06fa2210597656922
3
+ metadata.gz: ff5918a753301ad3ed7c86b86c73336a9a948724
4
+ data.tar.gz: 55ee964acc4b7708994f34cf74a1c6dbfffc265d
5
5
  SHA512:
6
- metadata.gz: e4340a006e1b04185798eb906819e00a2d92ab540139e45a0334c2b7cf295c855f9612af337ef1b9525f76c4d8e6b9fa5b066226726d24c98a2469ebcf398fdd
7
- data.tar.gz: 3bec35280bd3e7966aa078b00edb753a30bddca3a8a9ab1aa5af88d2fd711accb40f724dc4743947bfade229fa571868dafafe92069f39fbbaeb7b87f3df5533
6
+ metadata.gz: e1a2f39f04a46dd1ba4770d5c4f86df2ca220d70ffc37bc2e83f2be382dd8ed34bc93bdb8957c13a392e7e44616699a74e82e21d32da0068308970ae3e3695c7
7
+ data.tar.gz: 00ff99ae4f083d0ea658d8e4af803847bbd3dc24f2e596991bd2f13624f323879011c2a2c372ced679df74b086066acb5929a90a3a7e0ab2dff459d21c62eb6d
@@ -45,15 +45,16 @@ module HomeAssistant
45
45
  YAML.load_file(config['home_assistant_devices_file']).each do |name, conf|
46
46
  next unless conf['mac'] =~ /^(ble_|bt_)/i
47
47
  next unless conf['track']
48
- mac = conf.delete('mac').gsub(/^(ble_|bt_)/i, '').upcase
49
- conf['name'] = name # erase name with HA id
50
- devices[mac] = conf
51
- debug "Adding #{mac} (#{name}) found in known_devices.yaml"
48
+ mac = conf['mac'].gsub(/^(ble_|bt_)/i, '').upcase
49
+ conf['dev_id'] = name
50
+ devices[mac] = conf.select { |k, _v| %w(dev_id mac name).include? k }
51
+ debug "Adding #{mac} (#{conf['name']}) found in known_devices.yaml"
52
52
  end
53
53
  end
54
54
  if config['home_assistant_devices']
55
- config['home_assistant_devices'].each do |mac, name|
56
- devices[mac] = Mash.new(name: name)
55
+ config['home_assistant_devices'].each do |mac, _name|
56
+ ble_mac = "BLE_#{mac.upcase}" unless mac =~ /^(ble_|bt_)/i
57
+ devices[mac] = Mash.new(mac: ble_mac)
57
58
  end
58
59
  end
59
60
 
@@ -106,23 +107,13 @@ module HomeAssistant
106
107
  end
107
108
  end
108
109
 
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
110
  def update_home_assistant(ha_conf, state)
120
- ha_name = ha_conf['name']
121
- uri = URI.join(home_assistant_url, "api/states/device_tracker.#{ha_name}")
111
+ ha_conf['location_name'] = state
112
+ uri = URI.join(home_assistant_url, '/api/services/device_tracker/see')
122
113
  request = Net::HTTP::Post.new(uri)
123
114
  request.content_type = 'application/json'
124
115
  request['X-Ha-Access'] = home_assistant_password if home_assistant_password
125
- request.body = state_update(ha_conf, state)
116
+ request.body = ha_conf.to_json
126
117
  req_options = { use_ssl: uri.scheme == 'https' }
127
118
 
128
119
  response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
@@ -130,10 +121,10 @@ module HomeAssistant
130
121
  end
131
122
 
132
123
  if response.code.to_i == 200
133
- debug "State update #{state} sent to HA for #{ha_name}"
124
+ debug "State update #{state} sent to HA for #{ha_conf['dev_id']}"
134
125
  debug response.body
135
126
  else
136
- log "Error while sending #{state} to HA form #{ha_name}."
127
+ log "Error while sending #{state} to HA form #{ha_conf['dev_id']}."
137
128
  log "URI was: #{uri}. Response was:"
138
129
  log response.body
139
130
  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.32
4
+ version: 1.4.0.pre.alpha.pre.37
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-31 00:00:00.000000000 Z
11
+ date: 2017-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler