Sha256: 412b9d7b525363c8b6893d88bdef0948eff647b623005c43236c2121957acfda

Contents?: true

Size: 961 Bytes

Versions: 2

Compression:

Stored size: 961 Bytes

Contents

module MQTT
  module Homie
    class DeviceBuilder
      def initialize(options = {})
        @nodes = []
        @device_options = options
      end

      # create device and return it
      def build
        build_node if @node_data
        MQTT::Homie::Device.new(@device_options.merge(nodes: @nodes))
      end

      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

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

      private

      def build_node
        @nodes << MQTT::Homie::Node.new(@node_data.merge(properties: @properties))
        @node_data = nil
        @propertes = nil
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mqtt-homie-0.1.1 lib/mqtt/homie/device_builder.rb
mqtt-homie-0.1.0 lib/mqtt/homie/device_builder.rb