class Tinkerforge::BrickletRemoteSwitch
Controls remote mains switches
Constants
- CALLBACK_SWITCHING_DONE
This callback is triggered whenever the switching state changes from busy to ready, see
BrickletRemoteSwitch#get_switching_state
.
Public Class Methods
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
# File lib/tinkerforge/bricklet_remote_switch.rb, line 40 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
Public Instance Methods
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)
# File lib/tinkerforge/bricklet_remote_switch.rb, line 133 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
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|
# File lib/tinkerforge/bricklet_remote_switch.rb, line 162 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end
Returns the number of repeats as set by BrickletRemoteSwitch#set_repeats
.
# File lib/tinkerforge/bricklet_remote_switch.rb, line 92 def get_repeats check_validity send_request FUNCTION_GET_REPEATS, [], '', 9, 'C' end
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
.
# File lib/tinkerforge/bricklet_remote_switch.rb, line 73 def get_switching_state check_validity send_request FUNCTION_GET_SWITCHING_STATE, [], '', 9, 'C' end
Registers a callback with ID id
to the block block
.
# File lib/tinkerforge/bricklet_remote_switch.rb, line 167 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end
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.
# File lib/tinkerforge/bricklet_remote_switch.rb, line 85 def set_repeats(repeats) check_validity send_request FUNCTION_SET_REPEATS, [repeats], 'C', 8, '' end
This function is deprecated, use BrickletRemoteSwitch#switch_socket_a
instead.
# File lib/tinkerforge/bricklet_remote_switch.rb, line 61 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
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)
# File lib/tinkerforge/bricklet_remote_switch.rb, line 105 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
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)
# File lib/tinkerforge/bricklet_remote_switch.rb, line 120 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
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)
# File lib/tinkerforge/bricklet_remote_switch.rb, line 146 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