Module: MQTT::HomeAssistant::Homie::Property

Defined in:
lib/mqtt/home_assistant/homie/property.rb

Instance Method Summary collapse

Instance Method Details

#initialize(*args, hass: nil, **kwargs) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mqtt/home_assistant/homie/property.rb', line 7

def initialize(*args, hass: nil, **kwargs)
  super(*args, **kwargs)

  return unless hass

  case hass
  when Symbol
    public_send("hass_#{hass}")
  when Hash
    raise ArgumentError, "hass must only contain one item" unless hass.length == 1

    public_send("hass_#{hass.first.first}", **hass.first.last)
  else
    raise ArgumentError, "hass must be a Symbol or a Hash of HASS device type to additional HASS options"
  end
end

#publishObject



42
43
44
45
46
47
48
49
50
# File 'lib/mqtt/home_assistant/homie/property.rb', line 42

def publish
  super.tap do
    @pending_hass_registrations&.each do |entity|
      method = entity.delete(:method)
      HomeAssistant.public_send(method, self, **entity)
    end
    @pending_hass_registrations = nil
  end
end