mqtt-homeassistant 0.1.2 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4abb16dba6ea2ddab3b0619ded2e0712e2b997d710cc69d367a5234ee00371c
4
- data.tar.gz: b22f5a9ddc2fc216c8a57564f6691661fb0cbaeedfa00d3de76548cf23de299f
3
+ metadata.gz: 3d0d4267529911dcd46d67137facee40859218e31c1de6f7c057aaa536f302c2
4
+ data.tar.gz: 8f7ed7810a6ae5a4c2b03b3ca3e50954c654b29307c9c19bf31bd36671319293
5
5
  SHA512:
6
- metadata.gz: 9704e5112d570e0a7cdf255a365af0440a7a24c09376513703eb25726d46f180334e6c78f7ea6ad71ec2faa38adbdc511e4f453430f08840555d44276a1598d0
7
- data.tar.gz: ad8ce6569cbd7fccc1fa968061f4f9a966f97710d1d51d723128f67780191d32edeb5f6738f3eb5339d3a8305d9b2e3745b5e52cc92d2b816305e5010faff0a4
6
+ metadata.gz: 7ea2c835d1171876cf826a71e05e4b5cad925e1107c259d184f93b8fd1848870168c0cf9e84589e575c9db20ef185869e1c11b6a48e69459ba29d4c3576fa7a7
7
+ data.tar.gz: 383b55527730a79b6fc966061246df42d5e0d36daf8c604937dbd90f4e05e55c87101dfdad58003e20c21ea9212de0a670365fbd38b9cd49cb2f0c55483434e0
@@ -1,3 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- MQTT::Homie::Device.attr_accessor :home_assistant_device, :home_assistant_discovery_prefix
3
+ module MQTT
4
+ module Homie
5
+ class Device
6
+ attr_accessor :home_assistant_device, :home_assistant_discovery_prefix
7
+ end
8
+ end
9
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module MQTT
4
4
  module HomeAssistant
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.4"
6
6
  end
7
7
  end
@@ -105,7 +105,7 @@ module MQTT
105
105
  .merge({
106
106
  payload_off: "false",
107
107
  payload_on: "true",
108
- unique_id: "#{property.device.id}_#{property.node.id}_#{property.id}",
108
+ object_id: "#{property.node.id}_#{property.id}",
109
109
  state_topic: property.topic
110
110
  })
111
111
  config[:expire_after] = expire_after if expire_after
@@ -163,7 +163,8 @@ module MQTT
163
163
  device: device,
164
164
  entity_category: entity_category,
165
165
  icon: icon)
166
- config[:unique_id] = "#{node.device.id}_#{id || node.id}"
166
+
167
+ config[:object_id] = id || node.id
167
168
  read_only_props = %i[action current_temperature]
168
169
  properties.each do |prefix, property|
169
170
  add_property(config, property, prefix, templates: templates, read_only: read_only_props.include?(prefix))
@@ -258,7 +259,7 @@ module MQTT
258
259
  target_humidity_command_topic: "#{target_property.topic}/set",
259
260
  payload_off: "false",
260
261
  payload_on: "true",
261
- unique_id: "#{property.device.id}_#{id || property.node.id}"
262
+ object_id: id || property.node.id
262
263
  })
263
264
  add_property(config, property)
264
265
  add_property(config, target_property, :target_humidity)
@@ -306,7 +307,7 @@ module MQTT
306
307
  device: device,
307
308
  entity_category: entity_category,
308
309
  icon: icon)
309
- config[:unique_id] = "#{property.device.id}_#{property.node.id}_#{property.id}"
310
+ config[:object_id] = "#{property.node.id}_#{property.id}"
310
311
  add_property(config, property)
311
312
  case property.datatype
312
313
  when :boolean
@@ -354,7 +355,7 @@ module MQTT
354
355
  device: device,
355
356
  entity_category: entity_category,
356
357
  icon: icon)
357
- config[:unique_id] = "#{property.device.id}_#{property.node.id}_#{property.id}"
358
+ config[:object_id] = "#{property.node.id}_#{property.id}"
358
359
  add_property(config, property)
359
360
  config[:unit_of_measurement] = property.unit if property.unit
360
361
  if property.range
@@ -383,7 +384,7 @@ module MQTT
383
384
  device: device,
384
385
  entity_category: entity_category,
385
386
  icon: icon)
386
- config[:unique_id] = "#{property.device.id}_#{property.node.id}_#{property.id}"
387
+ config[:object_id] = "#{property.node.id}_#{property.id}"
387
388
  add_property(config, property)
388
389
  config[:payload_on] = property.range.first
389
390
 
@@ -406,7 +407,7 @@ module MQTT
406
407
  device: device,
407
408
  entity_category: entity_category,
408
409
  icon: icon)
409
- config[:unique_id] = "#{property.device.id}_#{property.node.id}_#{property.id}"
410
+ config[:object_id] = "#{property.node.id}_#{property.id}"
410
411
  add_property(config, property)
411
412
  config[:options] = property.range
412
413
 
@@ -440,7 +441,7 @@ module MQTT
440
441
  entity_category: entity_category,
441
442
  icon: icon)
442
443
  .merge({
443
- unique_id: "#{property.device.id}_#{property.node.id}_#{property.id}",
444
+ object_id: "#{property.node.id}_#{property.id}",
444
445
  state_topic: property.topic
445
446
  })
446
447
  config[:state_class] = state_class if state_class
@@ -468,7 +469,7 @@ module MQTT
468
469
  entity_category: entity_category,
469
470
  icon: icon)
470
471
  .merge({
471
- unique_id: "#{property.device.id}_#{property.node.id}_#{property.id}",
472
+ object_id: "#{property.node.id}_#{property.id}",
472
473
  payload_off: "false",
473
474
  payload_on: "true"
474
475
  })
@@ -514,6 +515,7 @@ module MQTT
514
515
 
515
516
  config = {
516
517
  name: name,
518
+ node_id: homie_device.id,
517
519
  availability_topic: "#{homie_device.topic}/$state",
518
520
  payload_available: "ready",
519
521
  payload_not_available: "lost",
@@ -533,7 +535,12 @@ module MQTT
533
535
  end
534
536
 
535
537
  def publish(mqtt, component, config, discovery_prefix:)
536
- mqtt.publish("#{discovery_prefix || "homeassistant"}/#{component}/#{config[:unique_id]}/config",
538
+ node_id, object_id = config.values_at(:node_id, :object_id)
539
+ config = config.dup
540
+ config[:unique_id] = "#{node_id}_#{object_id}"
541
+ config.delete(:node_id)
542
+ config.delete(:object_id)
543
+ mqtt.publish("#{discovery_prefix || "homeassistant"}/#{component}/#{node_id}/#{object_id}/config",
537
544
  config.to_json,
538
545
  retain: true,
539
546
  qos: 1)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mqtt-homeassistant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-10 00:00:00.000000000 Z
11
+ date: 2022-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: homie-mqtt
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  requirements: []
143
- rubygems_version: 3.1.2
143
+ rubygems_version: 3.3.7
144
144
  signing_key:
145
145
  specification_version: 4
146
146
  summary: Library for publishing device auto-discovery configuration for Home Assistant