module MQTT::Homie::HomieAttribute::ClassMethods

Public Instance Methods

homie_attr(name, options = {}) click to toggle source
# 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_list() click to toggle source
# File lib/mqtt/homie/homie_attribute.rb, line 31
def homie_attr_list
  @homie_attribute_list || []
end
homie_attr_options(name) click to toggle source
# 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?() click to toggle source
# File lib/mqtt/homie/homie_attribute.rb, line 27
def homie_has_id?
  !!homie_attr_list.detect { |i| i[0] == :id }
end
homie_id() click to toggle source
# 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