Sha256: 9993d806007743a7b6c2deaf5cb8a336c582a7e086d5a99a31d831dd58b02a8c
Contents?: true
Size: 1.68 KB
Versions: 3
Compression:
Stored size: 1.68 KB
Contents
#!/usr/bin/env ruby module X10 module Cm17a # A CM17A device that responds to on/off and adjust (brightness) # commands. # # Typical use: # # lamp = X10.device("a2") # Create the device # lamp.on # Turn the lamp on # lamp.adjust(-0.5) # Dim the lamp # lamp.off # Turn the lamp off # class Device attr_reader :address, :controller # Create a new X10 device using a CM17A protocol controller. # Such a device can handle on/off commands and simple dim # controls. # # Normally device objects are created through the X10 framework # and not directly by the client software. def initialize(house, unit, controller) @house = house @unit = unit @controller = controller @address = X10.make_address(house, unit) end # Turn the device on. def on @controller.command(@house, @unit, :on, 0) end # Turn the device off. def off @controller.command(@house, @unit, :off, 0) end # Adjust the brightness level by +steps+. If +steps+ is # positive, the brightness level is increased that many steps. # If +steps+ is negative, the brightness level is decreased by # <tt>|steps|</tt>. # # The controller limits the step size to 6, so larger steps must # be broken up. def step(steps) direction = (steps > 0) ? :brighten : :dim nsteps = steps.abs while nsteps > 0 n = (nsteps > 6) ? 6 : nsteps @controller.command(@house, @unit, direction, n) nsteps -= n end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
x10-cm17a-1.0.1-i386-mswin32 | lib/x10/cm17a_device.rb |
x10-cm17a-1.0.0 | lib/x10/cm17a_device.rb |
x10-cm17a-1.0.1 | lib/x10/cm17a_device.rb |