Class: Tinkerforge::BrickletRemoteSwitch

Inherits:
Device
  • Object
show all
Defined in:
lib/tinkerforge/bricklet_remote_switch.rb

Overview

Controls remote mains switches

Constant Summary collapse

DEVICE_IDENTIFIER =

:nodoc:

235
DEVICE_DISPLAY_NAME =

:nodoc:

'Remote Switch Bricklet'
CALLBACK_SWITCHING_DONE =

This callback is called whenever the switching state changes from busy to ready, see BrickletRemoteSwitch#get_switching_state.

3
FUNCTION_SWITCH_SOCKET =

:nodoc:

1
FUNCTION_GET_SWITCHING_STATE =

:nodoc:

2
FUNCTION_SET_REPEATS =

:nodoc:

4
FUNCTION_GET_REPEATS =

:nodoc:

5
FUNCTION_SWITCH_SOCKET_A =

:nodoc:

6
FUNCTION_SWITCH_SOCKET_B =

:nodoc:

7
FUNCTION_DIM_SOCKET_B =

:nodoc:

8
FUNCTION_SWITCH_SOCKET_C =

:nodoc:

9
FUNCTION_GET_IDENTITY =

:nodoc:

255
SWITCH_TO_OFF =

:nodoc:

0
SWITCH_TO_ON =

:nodoc:

1
SWITCHING_STATE_READY =

:nodoc:

0
SWITCHING_STATE_BUSY =

:nodoc:

1

Constants inherited from Device

Device::RESPONSE_EXPECTED_ALWAYS_FALSE, Device::RESPONSE_EXPECTED_ALWAYS_TRUE, Device::RESPONSE_EXPECTED_FALSE, Device::RESPONSE_EXPECTED_INVALID_FUNCTION_ID, Device::RESPONSE_EXPECTED_TRUE

Instance Attribute Summary

Attributes inherited from Device

#callback_formats, #expected_response_function_id, #expected_response_sequence_number, #registered_callbacks, #uid

Instance Method Summary collapse

Methods inherited from Device

#dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all

Constructor Details

#initialize(uid, ipcon) ⇒ BrickletRemoteSwitch

Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 39

def initialize(uid, ipcon)
  super uid, ipcon

  @api_version = [2, 0, 1]

  @response_expected[FUNCTION_SWITCH_SOCKET] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_SWITCHING_STATE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[CALLBACK_SWITCHING_DONE] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[FUNCTION_SET_REPEATS] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_REPEATS] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SWITCH_SOCKET_A] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_SWITCH_SOCKET_B] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_DIM_SOCKET_B] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_SWITCH_SOCKET_C] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_SWITCHING_DONE] = ''
end

Instance Method Details

#dim_socket_b(address, unit, dim_value) ⇒ Object

To control a type B dimmer you have to give the address, unit and the dim value you want to set the dimmer to.

The address has a range of 0 to 67108863 (26bit), the unit and the dim value has a range of 0 to 15 (4bit).

A detailed description on how you can teach a dimmer the address and unit can be found :ref:‘here <remote_switch_bricklet_type_b_address_and_unit>`.

.. versionadded

2.0.1$nbsp;(Plugin)



128
129
130
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 128

def dim_socket_b(address, unit, dim_value)
  send_request(FUNCTION_DIM_SOCKET_B, [address, unit, dim_value], 'L C C', 0, '')
end

#get_identityObject

Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.

The position can be ‘a’, ‘b’, ‘c’ or ‘d’.

The device identifier numbers can be found :ref:‘here <device_identifier>`. |device_identifier_constant|



154
155
156
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 154

def get_identity
  send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
end

#get_repeatsObject

Returns the number of repeats as set by BrickletRemoteSwitch#set_repeats.



86
87
88
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 86

def get_repeats
  send_request(FUNCTION_GET_REPEATS, [], '', 1, 'C')
end

#get_switching_stateObject

Returns the current switching state. If the current state is busy, the Bricklet is currently sending a code to switch a socket. It will not accept any calls of BrickletRemoteSwitch#switch_socket until the state changes to ready.

How long the switching takes is dependent on the number of repeats, see BrickletRemoteSwitch#set_repeats.



69
70
71
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 69

def get_switching_state
  send_request(FUNCTION_GET_SWITCHING_STATE, [], '', 1, 'C')
end

#register_callback(id, &block) ⇒ Object

Registers a callback with ID id to the block block.



159
160
161
162
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 159

def register_callback(id, &block)
  callback = block
  @registered_callbacks[id] = callback
end

#set_repeats(repeats) ⇒ Object

Sets the number of times the code is send when of the BrickletRemoteSwitch#switch_socket functions is called. The repeats basically correspond to the amount of time that a button of the remote is pressed.

Some dimmers are controlled by the length of a button pressed, this can be simulated by increasing the repeats.

The default value is 5.



81
82
83
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 81

def set_repeats(repeats)
  send_request(FUNCTION_SET_REPEATS, [repeats], 'C', 0, '')
end

#switch_socket(house_code, receiver_code, switch_to) ⇒ Object

This function is deprecated, use BrickletRemoteSwitch#switch_socket_a instead.



59
60
61
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 59

def switch_socket(house_code, receiver_code, switch_to)
  send_request(FUNCTION_SWITCH_SOCKET, [house_code, receiver_code, switch_to], 'C C C', 0, '')
end

#switch_socket_a(house_code, receiver_code, switch_to) ⇒ Object

To switch a type A socket you have to give the house code, receiver code and the state (on or off) you want to switch to.

The house code and receiver code have a range of 0 to 31 (5bit).

A detailed description on how you can figure out the house and receiver code can be found :ref:‘here <remote_switch_bricklet_type_a_house_and_receiver_code>`.

.. versionadded

2.0.1$nbsp;(Plugin)



99
100
101
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 99

def switch_socket_a(house_code, receiver_code, switch_to)
  send_request(FUNCTION_SWITCH_SOCKET_A, [house_code, receiver_code, switch_to], 'C C C', 0, '')
end

#switch_socket_b(address, unit, switch_to) ⇒ Object

To switch a type B socket you have to give the address, unit and the state (on or off) you want to switch to.

The address has a range of 0 to 67108863 (26bit) and the unit has a range of 0 to 15 (4bit). To switch all devices with the same address use 255 for the unit.

A detailed description on how you can teach a socket the address and unit can be found :ref:‘here <remote_switch_bricklet_type_b_address_and_unit>`.

.. versionadded

2.0.1$nbsp;(Plugin)



114
115
116
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 114

def switch_socket_b(address, unit, switch_to)
  send_request(FUNCTION_SWITCH_SOCKET_B, [address, unit, switch_to], 'L C C', 0, '')
end

#switch_socket_c(system_code, device_code, switch_to) ⇒ Object

To switch a type C socket you have to give the system code, device code and the state (on or off) you want to switch to.

The system code has a range of ‘A’ to ‘P’ (4bit) and the device code has a range of 1 to 16 (4bit).

A detailed description on how you can figure out the system and device code can be found :ref:‘here <remote_switch_bricklet_type_c_system_and_device_code>`.

.. versionadded

2.0.1$nbsp;(Plugin)



142
143
144
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 142

def switch_socket_c(system_code, device_code, switch_to)
  send_request(FUNCTION_SWITCH_SOCKET_C, [system_code, device_code, switch_to], 'k C C', 0, '')
end