lib/milight/v6/zone.rb in milight-v6-0.1.1 vs lib/milight/v6/zone.rb in milight-v6-0.2.0

- old
+ new

@@ -1,90 +1,95 @@ # frozen_string_literal: true module Milight module V6 + # Commands for lamps in a specific zone. class Zone attr_reader :zone_id def initialize(command, zone_id) @command = command @zone_id = zone_id end # Link/sync light bulbs. def link - @command.link(zone_id) + @command.execute(zone_id, [0x3D, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00]) self end # Unlink/clear light bulbs. def unlink - @command.unlink(zone_id) + @command.execute(zone_id, [0x3E, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00]) self end # Switch the lights on. def on - @command.on(zone_id) + @command.execute(zone_id, [0x31, 0x00, 0x00, 0x08, 0x04, 0x01, 0x00, 0x00, 0x00]) self end # Switch the lights off. def off - @command.off(zone_id) + @command.execute(zone_id, [0x31, 0x00, 0x00, 0x08, 0x04, 0x02, 0x00, 0x00, 0x00]) self end # Enable night light mode. def night_light - @command.night_light(zone_id) + @command.execute(zone_id, [0x31, 0x00, 0x00, 0x08, 0x04, 0x05, 0x00, 0x00, 0x00]) self end - # Set brightness, value: 0% to 100% + # Set brightness, value: 0% to 100%. def brightness(value) - @command.brightness(zone_id, value) + raise ArgumentError, "Please supply a brightness value between 0-100." if value.negative? || value > 100 + @command.execute(zone_id, [0x31, 0x00, 0x00, 0x08, 0x03, value, 0x00, 0x00, 0x00]) + self end # Set color temperature, value: 0 = 2700K, 100 = 6500K. def temperature(value) - @command.temperature(zone_id, value) + raise ArgumentError, "Please supply a temperature value between 0-100 (2700K to 6500K)." if value.negative? || value > 100 + @command.execute(zone_id, [0x31, 0x00, 0x00, 0x08, 0x05, value, 0x00, 0x00, 0x00]) + self end # Set color temperature to warm light (2700K). def warm_light - @command.temperature(zone_id, 0) - - self + temperature(0) end # Set color temperature to white (cool) light (6500K). def white_light - @command.temperature(zone_id, 100) - - self + temperature(100) end # Set the hue, value: 0 to 255 (red). # See Milight::V6::Color for predefined colors. def hue(value) - @command.hue(zone_id, value) + raise ArgumentError, "Please supply a hue value between 0-255." if value.negative? || value > 255 + @command.execute(zone_id, [0x31, 0x00, 0x00, 0x08, 0x01, value, value, value, value]) + self end # Set the saturation, value: 0% to 100%. def saturation(value) - @command.saturation(zone_id, value) + raise ArgumentError, "Please supply a saturation value between 0-100." if value.negative? || value > 100 + + @command.execute(zone_id, [0x31, 0x00, 0x00, 0x08, 0x02, value, 0x00, 0x00, 0x00]) self end # Wait before continuing to next command.