mqtt-homeassistant 0.1.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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.6
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-09 00:00:00.000000000 Z
11
+ date: 2025-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: homie-mqtt
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
- - !ruby/object:Gem::Dependency
42
- name: byebug
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '11.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '11.0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rake
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,35 +52,7 @@ dependencies:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
54
  version: '13.0'
69
- - !ruby/object:Gem::Dependency
70
- name: rubocop-inst
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.0'
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop-rake
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '0.6'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '0.6'
97
- description:
55
+ description:
98
56
  email: cody@cutrer.com'
99
57
  executables: []
100
58
  extensions: []
@@ -102,16 +60,14 @@ extra_rdoc_files: []
102
60
  files:
103
61
  - lib/mqtt-homeassistant.rb
104
62
  - lib/mqtt/home_assistant.rb
105
- - lib/mqtt/home_assistant/homie/device.rb
106
- - lib/mqtt/home_assistant/homie/node.rb
107
- - lib/mqtt/home_assistant/homie/property.rb
63
+ - lib/mqtt/home_assistant/client.rb
108
64
  - lib/mqtt/home_assistant/version.rb
109
65
  homepage: https://github.com/ccutrer/ruby-mqtt-homeassistant
110
66
  licenses:
111
67
  - MIT
112
68
  metadata:
113
69
  rubygems_mfa_required: 'true'
114
- post_install_message:
70
+ post_install_message:
115
71
  rdoc_options: []
116
72
  require_paths:
117
73
  - lib
@@ -126,8 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
82
  - !ruby/object:Gem::Version
127
83
  version: '0'
128
84
  requirements: []
129
- rubygems_version: 3.3.7
130
- signing_key:
85
+ rubygems_version: 3.5.11
86
+ signing_key:
131
87
  specification_version: 4
132
88
  summary: Library for publishing device auto-discovery configuration for Home Assistant
133
89
  via MQTT.
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
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
@@ -1,74 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MQTT
4
- module HomeAssistant
5
- module Homie
6
- module Node
7
- {
8
- climate: %i[action
9
- aux
10
- away_mode
11
- current_temperature
12
- fan_mode
13
- mode
14
- hold
15
- power
16
- swing_mode
17
- temperature
18
- temperature_high
19
- temperature_low],
20
- fan: [nil, :oscillation],
21
- humidifier: [nil, :target, :mode],
22
- light: [nil, :brightness, :color_mode, :color_temp, :effect, :hs, :rgb, :white, :xy]
23
- }.each do |(integration, properties)|
24
- has_nil = properties.include?(nil)
25
- method_arguments = []
26
- method_arguments << "property" if has_nil
27
- method_arguments.concat(properties.compact.map { |p| "#{p}_property: nil" })
28
- transforms = []
29
- transforms << "property = self[property] if property.is_a?(String)"
30
- transforms.concat(
31
- properties.compact.map do |p|
32
- "kwargs[:#{p}_property] = #{p}_property.is_a?(String) ? self[#{p}_property] : #{p}_property"
33
- end
34
- )
35
- args_code = has_nil ? "args = [property]" : "args = []"
36
-
37
- class_eval <<~RUBY, __FILE__, __LINE__ + 1
38
- def hass_#{integration}(#{method_arguments.join(", ")}, device: nil, discovery_prefix: nil, **kwargs)
39
- #{transforms.join("\n")}
40
- discovery_prefix ||= self.device.home_assistant_discovery_prefix
41
- device = self.device.home_assistant_device.merge(device || {}) if self.device.home_assistant_device
42
-
43
- kwargs[:device] = device
44
- kwargs[:discovery_prefix] = discovery_prefix
45
- #{args_code}
46
- if published?
47
- HomeAssistant.publish_#{integration}(*args, **kwargs)
48
- else
49
- pending_hass_registrations << [:publish_#{integration}, args, kwargs]
50
- end
51
- end
52
- RUBY
53
- end
54
-
55
- def publish
56
- super.tap do
57
- @pending_hass_registrations&.each do |(method, args, kwargs)|
58
- HomeAssistant.public_send(method, *args, **kwargs)
59
- end
60
- @pending_hass_registrations = nil
61
- end
62
- end
63
-
64
- private
65
-
66
- def pending_hass_registrations
67
- @pending_hass_registrations ||= []
68
- end
69
- end
70
- end
71
- end
72
- end
73
-
74
- MQTT::Homie::Node.prepend(MQTT::HomeAssistant::Homie::Node)
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MQTT
4
- module HomeAssistant
5
- module Homie
6
- module Property
7
- def initialize(*args, hass: nil, **kwargs)
8
- super(*args, **kwargs)
9
-
10
- return unless hass
11
-
12
- case hass
13
- when Symbol
14
- public_send("hass_#{hass}")
15
- when Hash
16
- raise ArgumentError, "hass must only contain one item" unless hass.length == 1
17
-
18
- public_send("hass_#{hass.first.first}", **hass.first.last)
19
- else
20
- raise ArgumentError, "hass must be a Symbol or a Hash of HASS device type to additional HASS options"
21
- end
22
- end
23
-
24
- %i[binary_sensor fan humidifier light number scene select sensor switch].each do |integration|
25
- class_eval <<~RUBY, __FILE__, __LINE__ + 1
26
- def hass_#{integration}(device: nil, discovery_prefix: nil, **kwargs)
27
- discovery_prefix ||= self.device.home_assistant_discovery_prefix
28
- device = self.device.home_assistant_device.merge(device || {}) if self.device.home_assistant_device
29
-
30
- kwargs[:device] = device
31
- kwargs[:discovery_prefix] = discovery_prefix
32
- if published?
33
- HomeAssistant.publish_#{integration}(self, **kwargs)
34
- else
35
- kwargs[:method] = :publish_#{integration}
36
- pending_hass_registrations << kwargs
37
- end
38
- end
39
- RUBY
40
- end
41
-
42
- def publish
43
- super.tap do
44
- @pending_hass_registrations&.each do |entity|
45
- method = entity.delete(:method)
46
- HomeAssistant.public_send(method, self, **entity)
47
- end
48
- @pending_hass_registrations = nil
49
- end
50
- end
51
-
52
- private
53
-
54
- def pending_hass_registrations
55
- @pending_hass_registrations ||= []
56
- end
57
- end
58
- end
59
- end
60
- end
61
-
62
- MQTT::Homie::Property.prepend(MQTT::HomeAssistant::Homie::Property)