Sha256: fe5a4c8a697948bbc3af64b4e6dc04c0680b0238bf37ba2bb2ba552f3acd1588

Contents?: true

Size: 645 Bytes

Versions: 1

Compression:

Stored size: 645 Bytes

Contents

module Yeelight
  class Lamp
    VALUES = '"rgb", "ct", "color_mode", "hue", "sat"'

    attr_reader :client

    def initialize(client)
      @client = client
    end

    def toggle_color(color_hex, duration = 1)
      color = "0x#{color_hex}".to_i(16)

      rgb, ct, color_mode, hue, sat = JSON.parse(client.get_prop(VALUES))['data']['result']

      client.set_rgb(color, 'smooth', 500)
      sleep duration

      case color_mode.to_i
      when 1
        client.set_rgb(rgb, 'smooth', 500)
      when 2
        client.set_ct_abx(ct, 'smooth', 500)
      when 3
        client.set_hsv(hue, sat, 'smooth', 500)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yeelight-lamp-client-0.1.0 lib/yeelight/lamp.rb