Module: MQTT::Homie::HomieAttribute::ClassMethods

Defined in:
lib/mqtt/homie/homie_attribute.rb

Instance Method Summary collapse

Instance Method Details

#homie_attr(name, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mqtt/homie/homie_attribute.rb', line 10

def homie_attr(name, options = {})
  # define accessors
  attr_reader name

  unless options[:immutable]
    define_method("#{name}=") { |value| homie_attr_set(name, value) }
  end

  # record attribute data
  @homie_attribute_list ||= []
  @homie_attribute_list << [name.to_sym, options]
end

#homie_attr_listObject



31
32
33
# File 'lib/mqtt/homie/homie_attribute.rb', line 31

def homie_attr_list
  @homie_attribute_list || []
end

#homie_attr_options(name) ⇒ Object



35
36
37
38
# File 'lib/mqtt/homie/homie_attribute.rb', line 35

def homie_attr_options(name)
  data = homie_attr_list.find { |i| i[0] == name } || []
  data[1] || {}
end

#homie_has_id?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/mqtt/homie/homie_attribute.rb', line 27

def homie_has_id?
  !!homie_attr_list.detect { |i| i[0] == :id }
end

#homie_idObject



23
24
25
# File 'lib/mqtt/homie/homie_attribute.rb', line 23

def homie_id
  homie_attr :id, required: true, validate: lambda { |i| valid_id?(i) }, immutable: true, hidden: true
end