class TiltHydrometer::MQTT

Public Class Methods

new(mqtt_uri, prefix) click to toggle source
# File lib/tilt_hydrometer/mqtt.rb, line 5
def initialize(mqtt_uri, prefix)
  @mqtt_uri = mqtt_uri
  @prefix = prefix
end

Public Instance Methods

publish(beacon) click to toggle source
# File lib/tilt_hydrometer/mqtt.rb, line 10
def publish(beacon)
  ::MQTT::Client.connect(@mqtt_uri) do |c|
    c.publish(topic(beacon), beacon_json(beacon), true)
  end
end

Private Instance Methods

beacon_json(beacon) click to toggle source
# File lib/tilt_hydrometer/mqtt.rb, line 22
def beacon_json(beacon)
  JSON.generate(
    temp_f: beacon.temp,
    temp_c: beacon.celsius,
    gravity_sg: beacon.gravity,
    gravity_p: beacon.plato
  )
end
topic(beacon) click to toggle source
# File lib/tilt_hydrometer/mqtt.rb, line 18
def topic(beacon)
  @prefix + beacon.color
end