Class: MQTT::Homie::DeviceBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/mqtt/homie/device_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DeviceBuilder

Returns a new instance of DeviceBuilder.



4
5
6
7
# File 'lib/mqtt/homie/device_builder.rb', line 4

def initialize(options = {})
  @nodes = []
  @device_options = options
end

Instance Method Details

#buildObject

create device and return it



10
11
12
13
# File 'lib/mqtt/homie/device_builder.rb', line 10

def build
  build_node if @node_data
  MQTT::Homie::Device.new(@device_options.merge(nodes: @nodes))
end

#node(options = {}) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/mqtt/homie/device_builder.rb', line 15

def node(options = {})
  raise "node key/value list expected" unless options.kind_of?(Hash)
  build_node if @node_data
  @node_data = options
  @properties = []
  self
end

#property(options = {}) ⇒ Object



23
24
25
26
27
# File 'lib/mqtt/homie/device_builder.rb', line 23

def property(options = {})
  raise "property key/value list expected" unless options.kind_of?(Hash)
  @properties << MQTT::Homie::Property.new(options)
  self
end