Skip to content

Commit

Permalink
Add all focuser specific methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sergio1990 committed Jul 15, 2022
1 parent b336fea commit 3f6c31e
Show file tree
Hide file tree
Showing 4 changed files with 291 additions and 15 deletions.
104 changes: 104 additions & 0 deletions lib/alpaca_device/device_api/v1/focuser_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,125 @@

require 'grape'

require_relative '../../helpers/shared_params'

module AlpacaDevice
module DeviceApi
module V1
class FocuserApi < Grape::API
helpers AlpacaDevice::Helpers::SharedParams
helpers do
def current_ascom_type
AlpacaDevice::AscomDevices::Type::FOCUSER
end
end

params do
use :client_transaction_info
end
get :position do
success_response(
'Value' => current_ascom_device.position
)
end

params do
use :client_transaction_info
end
get :absolute do
success_response(
'Value' => current_ascom_device.absolute
)
end

params do
use :client_transaction_info
end
get :ismoving do
success_response(
'Value' => current_ascom_device.ismoving
)
end

params do
use :client_transaction_info
end
get :maxincrement do
success_response(
'Value' => current_ascom_device.maxincrement
)
end

params do
use :client_transaction_info
end
get :maxstep do
success_response(
'Value' => current_ascom_device.maxstep
)
end

params do
use :client_transaction_info
end
get :stepsize do
success_response(
'Value' => current_ascom_device.stepsize
)
end

params do
use :client_transaction_info
end
get :tempcomp do
success_response(
'Value' => current_ascom_device.tempcomp
)
end

params do
requires :TempComp, type: Boolean
use :client_transaction_info
end
put :tempcomp do
current_ascom_device.set_tempcomp(tempcomp: params[:TempComp])
success_response
end

params do
use :client_transaction_info
end
get :tempcompavailable do
success_response(
'Value' => current_ascom_device.tempcompavailable
)
end

params do
use :client_transaction_info
end
get :temperature do
success_response(
'Value' => current_ascom_device.temperature
)
end

params do
use :client_transaction_info
end
put :halt do
current_ascom_device.set_halt
success_response
end

params do
requires :Position, type: Integer
use :client_transaction_info
end
put :move do
current_ascom_device.set_move(position: params[:Position])
success_response
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class TestDeviceApiV1 < Minitest::Test
class TestDeviceCommonApiV1 < Minitest::Test
include Rack::Test::Methods

def app
Expand All @@ -21,20 +21,6 @@ def test_connected
assert_equal false, value
end

def test_position
get '/api/v1/focuser/0/position', {
:ClientID => 123,
:ClientTransactionID => 890
}
assert last_response.ok?
assert_transaction_info(890)

value = json_response[:Value]

refute_nil value
assert_equal 0, value
end

def test_description
get '/api/v1/focuser/0/description', {
:ClientID => 123,
Expand Down
178 changes: 178 additions & 0 deletions test/api/test_device_focuser_api_v1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
require "test_helper"

class TestDeviceFocuserApiV1 < Minitest::Test
include Rack::Test::Methods

def app
AlpacaDevice::Api
end

def test_position
get '/api/v1/focuser/0/position', {
:ClientID => 123,
:ClientTransactionID => 890
}
assert last_response.ok?
assert_transaction_info(890)

value = json_response[:Value]

refute_nil value
assert_equal 0, value
end

def test_absolute
get '/api/v1/focuser/0/absolute', {
:ClientID => 123,
:ClientTransactionID => 890
}
assert last_response.ok?
assert_transaction_info(890)

value = json_response[:Value]

refute_nil value
assert_equal false, value
end

def test_ismoving
get '/api/v1/focuser/0/ismoving', {
:ClientID => 123,
:ClientTransactionID => 890
}
assert last_response.ok?
assert_transaction_info(890)

value = json_response[:Value]

refute_nil value
assert_equal false, value
end

def test_maxincrement
get '/api/v1/focuser/0/maxincrement', {
:ClientID => 123,
:ClientTransactionID => 890
}
assert last_response.ok?
assert_transaction_info(890)

value = json_response[:Value]

refute_nil value
assert_equal 100, value
end

def test_maxstep
get '/api/v1/focuser/0/maxstep', {
:ClientID => 123,
:ClientTransactionID => 890
}
assert last_response.ok?
assert_transaction_info(890)

value = json_response[:Value]

refute_nil value
assert_equal 65535, value
end

def test_stepsize
get '/api/v1/focuser/0/stepsize', {
:ClientID => 123,
:ClientTransactionID => 890
}
assert last_response.ok?
assert_transaction_info(890)

value = json_response[:Value]

refute_nil value
assert_equal 4, value
end

def test_tempcomp
get '/api/v1/focuser/0/tempcomp', {
:ClientID => 123,
:ClientTransactionID => 890
}
assert last_response.ok?
assert_transaction_info(890)

value = json_response[:Value]

refute_nil value
assert_equal false, value
end

def test_set_tempcomp
put '/api/v1/focuser/0/tempcomp', {
:TempComp => true,
:ClientID => 123,
:ClientTransactionID => 890
}
assert last_response.ok?
assert_transaction_info(890)
end

def test_set_tempcomp_failure
put '/api/v1/focuser/0/tempcomp', {
:ClientID => 123,
:ClientTransactionID => 890
}
refute last_response.ok?
end

def test_tempcompavailable
get '/api/v1/focuser/0/tempcompavailable', {
:ClientID => 123,
:ClientTransactionID => 890
}
assert last_response.ok?
assert_transaction_info(890)

value = json_response[:Value]

refute_nil value
assert_equal false, value
end

def test_temperature
get '/api/v1/focuser/0/temperature', {
:ClientID => 123,
:ClientTransactionID => 890
}
assert last_response.ok?
assert_transaction_info(890)

value = json_response[:Value]

refute_nil value
assert_equal 20, value
end

def test_set_halt
put '/api/v1/focuser/0/halt', {
:ClientID => 123,
:ClientTransactionID => 890
}
assert last_response.ok?
end

def test_set_move
put '/api/v1/focuser/0/move', {
:Position => 300,
:ClientID => 123,
:ClientTransactionID => 890
}
assert last_response.ok?
end

def test_set_move_failure
put '/api/v1/focuser/0/move', {
:ClientID => 123,
:ClientTransactionID => 890
}
refute last_response.ok?
end
end
8 changes: 8 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ def initialize
@driverversion = "1.0"
@interfaceversion = 3
@supportedactions = []
@absolute = false
@ismoving = false
@maxincrement = 100
@maxstep = 65535
@stepsize = 4
@tempcomp = false
@tempcompavailable = false
@temperature = 20
end

def set_tempcomp(tempcomp:)
Expand Down

0 comments on commit 3f6c31e

Please sign in to comment.