Sha256: 0919b3b0514d96987e9dd6b3de8370e9ce628fd1e06a9676323edc0f498a3bae

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

require 'milight/colour'

module Milight
  class RgbwAll

    ALL_OFF  = 0x41
    ALL_ON   = 0x42
    WHITE = 0xC2
    COLOUR = 0x40
    BRIGHTNESS = 0x4E

    def initialize(commander, colour_helper: Milight::Colour)
      @commander = commander
      @colour_helper = colour_helper
    end

    def on
      @commander.send_command ALL_ON
      self
    end

    def off
      @commander.send_command ALL_OFF
      self
    end

    def white
      send_white_cmd
      self
    end

    def hue(hue)
      colour = @colour_helper.new(hue)
      send_colour_cmd colour
      self
    end

    def brightness(value)
      brightness = Milight::Brightness.new(value)
      send_brightness_cmd brightness
      self
    end

    def colour(colour)
      colour_value = @colour_helper.new(colour)
      colour_value.greyscale? ? send_white_cmd : send_colour_cmd(colour_value)
      send_brightness_cmd colour_value
      self
    end

    private

    def send_white_cmd
      select
      @commander.send_command WHITE
    end

    def send_colour_cmd colour
      select
      @commander.send_command COLOUR, colour.to_milight_colour
    end

    def send_brightness_cmd brightness
      select
      @commander.send_command BRIGHTNESS, brightness.to_milight_brightness
    end

    def select
      on
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
milight-easybulb-1.0.0 lib/milight/rgbw_all.rb