Skip to content

Commit

Permalink
Corrected INSTEON direct command.
Browse files Browse the repository at this point in the history
  • Loading branch information
fixermark committed Jun 25, 2012
1 parent bc0a512 commit c84e577
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 24 deletions.
Binary file modified belphanior-x10-servant-0.0.1.gem
Binary file not shown.
101 changes: 85 additions & 16 deletions bin/belphanior-x10-servant
Expand Up @@ -3,6 +3,7 @@ require 'rubygems'
require 'belphanior/servant/servant'
require 'belphanior/servant/homenetwork/insteon_2412n_marshaller'
require 'belphanior/servant/homenetwork/insteon_2412n_x10_codec'
require 'belphanior/servant/homenetwork/insteon_2412n_insteon_codec'
require 'sinatra'

# Must be called to install and configure default routing for
Expand All @@ -13,12 +14,14 @@ if servant_config.get("insteon_host") == nil
servant_config.set("insteon_host","localhost")
end

marshaller = Belphanior::Servant::HomeNetwork::Insteon_2412n_Marshaller.new(
marshaller = Belphanior::Servant::HomeNetwork::Insteon_2412n_Marshaller.new(
servant_config.get("insteon_host"))

set(:marshaller, marshaller)
set(:x10, Belphanior::Servant::HomeNetwork::Insteon_2412n_x10_Codec.new(
marshaller))
set(:insteon, Belphanior::Servant::HomeNetwork::Insteon_2412n_Insteon_Codec.new(
marshaller))

device_id_arg = {
"name" => "device",
Expand All @@ -30,27 +33,93 @@ add_role_description(
"name" => "x10 controller",
"description" => "A controller for X10 devices, which can address the devices by house code and unit code.",
"commands" => [
{
"name" => "unit on",
"description" => "Turn on the designated unit.",
"arguments" => [device_id_arg],
"return" => "None."
},
{
"name" => "unit off",
"description" => "Turn off the designated unit.",
"arguments" => [device_id_arg],
"return" => "None."
}
]
{
"name" => "unit on",
"description" => "Turn on the designated unit.",
"arguments" => [device_id_arg],
"return" => "None."
},
{
"name" => "unit off",
"description" => "Turn off the designated unit.",
"arguments" => [device_id_arg],
"return" => "None."
}
]
})

add_handler("unit on", "device", "POST", "/device/$(device)/on", "") { |device|
add_role_description(
{
"name" => "insteon controller",
"description" => "A controller for INSTEON devices, which are addressed by a six-character hex string.",
"commands" => [
{
"name" => "turn on",
"description" => "Turn on the designated unit.",
"arguments" => [
{
"name" => "device",
"description" => "The six-character address of the device."
}
],
"return" => "None."
},
{
"name" => "turn off",
"description" => "Turn off the designated unit.",
"arguments" => [
{
"name" => "device",
"description" => "The six-character address of the device."
}
],
"return" => "None."
},
{
"name" => "set brightness",
"description" => "Sets the brightness of the device.",
"arguments" => [
{
"name" => "device",
"description" => "The six-character address of the device."
},
{
"name" => "brightness",
"description" => "Brightness level, between 0 and 1."
}
],
"return" => "None."
}
]
})


add_handler("unit on", "device", "POST", "/device/$(device)/on", "", 0) { |device|
settings.x10.device_on(device)
""
}

add_handler("unit off", "device", "POST", "/device/$(device)/off", "") { |device|
add_handler("unit off", "device", "POST", "/device/$(device)/off", "", 0) { |device|
settings.x10.device_off(device)
""
}

add_handler("turn on", "device", "POST", "/insteon/$(device)/on", "", 1) { |device|
settings.insteon.device_on(device)
""
}

add_handler("turn off", "device", "POST", "/insteon/$(device)/off", "", 1) { |device|
settings.insteon.device_off(device)
""
}

add_handler(
"set brightness",
["device", "brightness"],
"POST", "/insteon/$(device)/brightness",
"$(brightness)", 1) { |device|
brightness = (request.body.read).to_f
settings.insteon.device_set_brightness(device, brightness)
""
}
Expand Up @@ -45,7 +45,7 @@ def device_set_brightness(address, brightness)

# sends command to device specified by address.
def send_command(address, command, brightness_code)
@marshaller.send(INSTEON_PREFIX + address +
@marshaller.send(INSTEON_PREFIX + address + "0F" +
COMMAND_CODE_TABLE[command] + brightness_code)
end

Expand Down
Expand Up @@ -20,38 +20,38 @@ def test_on_off
fast_on_code = "12"
fast_off_code = "14"
@marshaller.expects(:send).with(
@insteon_prefix + address + fast_on_code + "FF")
@insteon_prefix + address + "0F" + fast_on_code + "FF")
@codec.device_on(address)
end

def test_brightness
address = "001122"
on_code = "11"
@marshaller.expects(:send).with(
@insteon_prefix + address + on_code + "00")
@insteon_prefix + address + "0F" + on_code + "00")
@codec.device_set_brightness(address, 0)

@marshaller.expects(:send).with(
@insteon_prefix + address + on_code + "FF")
@insteon_prefix + address + "0F" + on_code + "FF")
@codec.device_set_brightness(address, 1)

# Exact equality
@marshaller.expects(:send).with(
@insteon_prefix + address + on_code + "7F")
@insteon_prefix + address + "0F" + on_code + "7F")
@codec.device_set_brightness(address, 0.5)

# Near-equality
@marshaller.expects(:send).with(
@insteon_prefix + address + on_code + "7F")
@insteon_prefix + address + "0F" + on_code + "7F")
@codec.device_set_brightness(address, 0.4)

# Out of bounds
@marshaller.expects(:send).with(
@insteon_prefix + address + on_code + "00")
@insteon_prefix + address + "0F" + on_code + "00")
@codec.device_set_brightness(address, -1)

@marshaller.expects(:send).with(
@insteon_prefix + address + on_code + "FF")
@insteon_prefix + address + "0F" + on_code + "FF")
@codec.device_set_brightness(address, 1.5)
end
end

0 comments on commit c84e577

Please sign in to comment.