Sha256: ed5487f873e09eeb59ae50449190c557e237b71ab89844a8e58d40dfd689a0dd

Contents?: true

Size: 451 Bytes

Versions: 1

Compression:

Stored size: 451 Bytes

Contents

# frozen_string_literal: true
require 'mqtt'

module RgRefresh
  class PublishWrapper
    attr_reader :client, :topic, :messages

    def initialize(opts)
      @client = MQTT::Client.connect(opts.fetch(:client))
      @topic = opts.fetch(:topic)
      @messages = opts.fetch(:messages)
    end

    def transition_to(mode)
      client.publish(topic, messages.fetch(mode))
    end

    def finish
      client.disconnect
    rescue
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rg_refresh-0.1.2 lib/rg_refresh/publish_wrapper.rb