Class: X10::Cm17a::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/x10/cm17a_device.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(house, unit, controller) ⇒ Device

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.



26
27
28
29
30
31
# File 'lib/x10/cm17a_device.rb', line 26

def initialize(house, unit, controller)
	@house = house
	@unit = unit
	@controller = controller
	@address = X10.make_address(house, unit)
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



18
19
20
# File 'lib/x10/cm17a_device.rb', line 18

def address
  @address
end

#controllerObject (readonly)

Returns the value of attribute controller.



18
19
20
# File 'lib/x10/cm17a_device.rb', line 18

def controller
  @controller
end

Instance Method Details

#offObject

Turn the device off.



39
40
41
# File 'lib/x10/cm17a_device.rb', line 39

def off
	@controller.command(@house, @unit, :off, 0)
end

#onObject

Turn the device on.



34
35
36
# File 'lib/x10/cm17a_device.rb', line 34

def on
	@controller.command(@house, @unit, :on, 0)
end

#step(steps) ⇒ Object

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

|steps|.

The controller limits the step size to 6, so larger steps must be broken up.



50
51
52
53
54
55
56
57
58
# File 'lib/x10/cm17a_device.rb', line 50

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