Class: Tinkerforge::BrickletRemoteSwitch
- 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 triggered 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::DEVICE_IDENTIFIER_CHECK_MATCH, Device::DEVICE_IDENTIFIER_CHECK_MISMATCH, Device::DEVICE_IDENTIFIER_CHECK_PENDING, 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, #high_level_callbacks, #registered_callbacks, #replaced, #uid
Instance Method Summary collapse
-
#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.
-
#get_identity ⇒ Object
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.
-
#get_repeats ⇒ Object
Returns the number of repeats as set by BrickletRemoteSwitch#set_repeats.
-
#get_switching_state ⇒ Object
Returns the current switching state.
-
#initialize(uid, ipcon) ⇒ BrickletRemoteSwitch
constructor
Creates an object with the unique device ID
uid
and adds it to the IP Connectionipcon
. -
#register_callback(id, &block) ⇒ Object
Registers a callback with ID
id
to the blockblock
. -
#set_repeats(repeats) ⇒ Object
Sets the number of times the code is sent when one of the switch socket functions is called.
-
#switch_socket(house_code, receiver_code, switch_to) ⇒ Object
This function is deprecated, use BrickletRemoteSwitch#switch_socket_a instead.
-
#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.
-
#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.
-
#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.
Methods inherited from Device
#check_validity, #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
.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 41 def initialize(uid, ipcon) super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME @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[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] = [8, ''] @ipcon.add_device self 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.
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)
134 135 136 137 138 |
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 134 def dim_socket_b(address, unit, dim_value) check_validity send_request FUNCTION_DIM_SOCKET_B, [address, unit, dim_value], 'L C C', 8, '' end |
#get_identity ⇒ Object
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’, ‘d’, ‘e’, ‘f’, ‘g’ or ‘h’ (Bricklet Port). A Bricklet connected to an :ref:‘Isolator Bricklet <isolator_bricklet>` is always at position ’z’.
The device identifier numbers can be found :ref:‘here <device_identifier>`. |device_identifier_constant|
163 164 165 |
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 163 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end |
#get_repeats ⇒ Object
Returns the number of repeats as set by BrickletRemoteSwitch#set_repeats.
93 94 95 96 97 |
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 93 def get_repeats check_validity send_request FUNCTION_GET_REPEATS, [], '', 9, 'C' end |
#get_switching_state ⇒ Object
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 requests to switch sockets until the state changes to ready.
How long the switching takes is dependent on the number of repeats, see BrickletRemoteSwitch#set_repeats.
74 75 76 77 78 |
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 74 def get_switching_state check_validity send_request FUNCTION_GET_SWITCHING_STATE, [], '', 9, 'C' end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id
to the block block
.
168 169 170 171 |
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 168 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |
#set_repeats(repeats) ⇒ Object
Sets the number of times the code is sent when one of the 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.
86 87 88 89 90 |
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 86 def set_repeats(repeats) check_validity send_request FUNCTION_SET_REPEATS, [repeats], 'C', 8, '' end |
#switch_socket(house_code, receiver_code, switch_to) ⇒ Object
This function is deprecated, use BrickletRemoteSwitch#switch_socket_a instead.
62 63 64 65 66 |
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 62 def switch_socket(house_code, receiver_code, switch_to) check_validity send_request FUNCTION_SWITCH_SOCKET, [house_code, receiver_code, switch_to], 'C C C', 8, '' 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.
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)
106 107 108 109 110 |
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 106 def switch_socket_a(house_code, receiver_code, switch_to) check_validity send_request FUNCTION_SWITCH_SOCKET_A, [house_code, receiver_code, switch_to], 'C C C', 8, '' 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.
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)
121 122 123 124 125 |
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 121 def switch_socket_b(address, unit, switch_to) check_validity send_request FUNCTION_SWITCH_SOCKET_B, [address, unit, switch_to], 'L C C', 8, '' 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.
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)
147 148 149 150 151 |
# File 'lib/tinkerforge/bricklet_remote_switch.rb', line 147 def switch_socket_c(system_code, device_code, switch_to) check_validity send_request FUNCTION_SWITCH_SOCKET_C, [system_code, device_code, switch_to], 'k C C', 8, '' end |