pypck.pck_commands
¶
PCK command parsers and generators.
- class pypck.pck_commands.PckGenerator¶
Helpers to generate LCN-PCK commands.
LCN-PCK is the command-syntax used by LCN-PCHK to send and receive LCN commands.
- static activate_scene_output(scene_id: int, output_ports: Sequence[OutputPort] = (), ramp: int | None = None) str ¶
Activate the stored output states for the given scene.
Please note: The output ports 3 and 4 can only be activated simultaneously. If one of them is given, the other one is activated, too.
- Parameters:
scene_id (int) – Scene id 0..9
output_ports (list(OutputPort)) – Output ports to activate as list
ramp (int) – Ramp value
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static activate_scene_relay(scene_id: int, relay_ports: Sequence[RelayPort] = ()) str ¶
Activate the stored relay states for the given scene.
- Parameters:
scene_id (int) – Scene id 0..9
relay_ports (list(RelayPort)) – Relay ports to activate as list
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static beep(sound: BeepSound, count: int) str ¶
Make count number of beep sounds.
- Parameters:
sound (BeepSound) – Beep sound style
count (int) – Number of beeps (1..15)
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static change_scene_register(register_id: int) str ¶
Change the active scene register.
- Parameters:
register_id (int) – Register id 0..9
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static control_led(led_id: int, state: LedStatus) str ¶
Generate a command to the set the state of a single LED.
- Parameters:
led_id (int) – Led id 0..11
state (LedStatus) – The state to set
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static control_motors_outputs(state: MotorStateModifier, reverse_time: MotorReverseTime | None = None) str ¶
Generate a command to control a motor via output ports 1+2.
- Parameters:
state (MotorStateModifier) – The modifier for the motor state
reverse_time (MotorReverseTime) – Reverse time for modules with FW<190C
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static control_motors_relays(states: list[MotorStateModifier]) str ¶
Generate a command to control motors via relays.
- Parameters:
states (MotorStateModifier) – The 4 modifiers for the motor states as a list
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static control_relays(states: list[RelayStateModifier]) str ¶
Generate a command to control relays.
- Parameters:
states (RelayStateModifier) – The 8 modifiers for the relay states as a list
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static control_relays_timer(time_msec: int, states: list[RelayStateModifier]) str ¶
Generate a command to control relays.
- Parameters:
time_msec (int) – Duration of timer in milliseconds
states (RelayStateModifier) – The 8 modifiers for the relay states as a list (only ON and OFF allowed)
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static dim_all_outputs(percent: float, ramp: int, software_serial: int) str ¶
Generate a dim command for all output-ports.
- Parameters:
percent (float) – Brightness in percent 0..100
ramp (int) – Ramp value
software_serial (int) – The expected firmware version of all receiving modules.
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static dim_output(output_id: int, percent: float, ramp: int) str ¶
Generate a dim command for a single output-port.
- Parameters:
output_id (int) – Output id 0..3
percent (float) – Brightness in percent 0..100
ramp (int) – Ramp value
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static dyn_text_part(row_id: int, part_id: int, part: bytes) bytes ¶
Generate the command header / start for sending dynamic texts.
Used by LCN-GTxD periphery (supports 4 text rows). To complete the command, the text to send must be appended (UTF-8 encoding). Texts are split up into up to 5 parts with 12 “UTF-8 bytes” each.
- Parameters:
row_id (int) – Row id 0..3
part_id (int) – Part id 0..4
part (bytes) – Text part (up to 12 bytes), encoded as lcn_defs.LCN_ENCODING
- Returns:
The PCK command (without address header) as encoded bytes
- Return type:
bytes
- static empty() str ¶
Generate an empty command (LEER) that does nothing.
Combine with request for acknowledgement to discover and ping modules and to discover and verify group memberships.
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static generate_address_header(addr: LcnAddr, local_seg_id: int, wants_ack: bool) str ¶
Generate a PCK command address header.
- Parameters:
addr (
LcnAddr
) – The module’s/group’s addresslocal_seg_id (int) – The local segment id
wants_ack (bool) – Is an acknowledge requested.
- Returns:
The PCK address header string.
- Return type:
str
- static lock_keys(table_id: int, states: list[KeyLockStateModifier]) str ¶
Generate a command to lock keys.
- Parameters:
table_id (int) – Table id 0(A)..3(D)
states (list(bool)) – The 8 key-lock modifiers as list
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static lock_keys_tab_a_temporary(time: int, time_unit: TimeUnit, keys: list[bool]) str ¶
Generate a command to lock keys for table A temporary.
There is no hardware-support for locking tables B-D.
- Parameters:
time (int) – The lock time
time_unit (TimeUnit) – The time unit
keys (list(bool)) – The 8 key-lock states (True means lock) as list
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static lock_regulator(reg_id: int, state: bool) str ¶
Generate a command to lock a regulator.
- Parameters:
reg_id (int) – Regulator id 0..1
state (bool) – The lock state
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static ping(counter: int) str ¶
Generate a keep-alive.
LCN-PCHK will close the connection if it does not receive any commands specific period (10 minutes by default).
- Parameters:
counter (int) – The current ping’s id (optional, but ‘best practice’). Should start with 1
- Returns:
The PCK command as text
- Return type:
str
- static rel_output(output_id: int, percent: float) str ¶
Generate a command to change the value of an output-port.
- Parameters:
output_id (int) – Output id 0..3
percent (float) – Relative percentage -100..100
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static request_bin_sensors_status() str ¶
Generate a binary-sensors status request.
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static request_comment(block_id: int) str ¶
Generate a comment request.
:return The PCK command (without address header) as text :rtype: str
- static request_group_membership_dynamic() str ¶
Generate a group membership request for dynamic membership.
:return The PCK command (without address header) as text :rtype: str
- static request_group_membership_static() str ¶
Generate a group membership request for static membership (EEPROM).
:return The PCK command (without address header) as text :rtype: str
- static request_key_lock_status() str ¶
Generate a request for key-lock states.
Always requests table A-D. Supported since LCN-PCHK 2.8.
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static request_leds_and_logic_ops() str ¶
Generate a request for LED and logic-operations states.
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static request_name(block_id: int) str ¶
Generate a name request.
:return The PCK command (without address header) as text :rtype: str
- static request_oem_text(block_id: int) str ¶
Generate an oem text request.
:return The PCK command (without address header) as text :rtype: str
- static request_output_status(output_id: int) str ¶
Generate an output-port status request.
- Parameters:
output_id (int) – Output id 0..3
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static request_relays_status() str ¶
Generate a relays-status request.
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static request_serial() str ¶
Generate a firmware/serial-number request.
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static request_status_scene(register_id: int, scene_id: int) str ¶
Request the stored output and ramp values for the given scene.
- Parameters:
register_id (int) – Register id 0..9
register_id – Scene id 0..9
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static request_var_status(var: Var, software_serial: int) str ¶
Generate a variable value request.
- Parameters:
var (Var) – The variable to request
software_serial (int) – The target module’s firmware version
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static segment_coupler_scan() str ¶
Generate a scan-command for LCN segment-couplers.
Used to detect the local segment (where the physical bus connection is located).
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static send_keys(cmds: list[SendKeyCommand], keys: list[bool]) str ¶
Generate a command to send LCN keys.
- Parameters:
cmds (SendKeyCommand) – The 4 concrete commands to send for the tables (A-D) as list
keys (list(bool)) – The tables’ 8 key-states (True means “send”) as list
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static send_keys_hit_deferred(table_id: int, time: int, time_unit: TimeUnit, keys: list[bool]) str ¶
Generate a command to send LCN keys deferred / delayed.
- Parameters:
table_id (int) – Table id 0(A)..3(D)
time (int) – The delay time
time_unit (TimeUnit) – The time unit
keys (list(bool)) – The table’s 8 key-states (True means “send”) as list
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static set_dec_mode() str ¶
Generate PCK command to set used number system to decimal.
- static set_operation_mode(dim_mode: OutputPortDimMode, status_mode: OutputPortStatusMode) str ¶
Generate a PCK command to set the connection’s operation mode.
This influences how output-port commands and status are interpreted and must be in sync with the LCN bus.
- Parameters:
dimMode (OuputPortDimMode) – The dimming mode (50/200 steps)
statusMode (OutputPortStatusMode) – The status mode (percent/native)
- Returns:
The PCK command as text
- Return type:
str
- static store_scene_output(scene_id: int, output_ports: Sequence[OutputPort] = (), ramp: int | None = None) str ¶
Store the current output states in the given scene.
Please note: The output ports 3 and 4 can only be stored simultaneously. If one of them is given, the other one is stored, too.
- Parameters:
scene_id (int) – Scene id 0..9
output_ports (list(OutputPort)) – Output ports to store as list
ramp (int) – Ramp value
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static store_scene_outputs_direct(register_id: int, scene_id: int, percents: Sequence[float], ramps: Sequence[int]) str ¶
Store the given output values and ramps in the given scene.
- Parameters:
register_id (int) – Register id 0..9
scene_id (int) – Scene id 0..9
percents (list(float)) – Output values in percent as list
ramp (list(int)) – Ramp values as list
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static store_scene_relay(scene_id: int, relay_ports: Sequence[RelayPort] = ()) str ¶
Store the current relay states in the given scene.
- Parameters:
scene_id (int) – Scene id 0..9
relay_ports (list(RelayPort)) – Relay ports to store as list
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static toggle_all_outputs(ramp: int) str ¶
Generate a command that toggles all output-ports.
Toggle mode: (on->off, off->on).
- Parameters:
ramp (int) – Ramp value
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static toggle_output(output_id: int, ramp: int) str ¶
Generate a command that toggles a single output-port.
Toggle mode: (on->off, off->on).
- Parameters:
output_id (int) – Output id 0..3
ramp (int) – Ramp value
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static update_status_var(var: Var, value: int) str ¶
Generate a command that send variable status updates.
PCHK provides this variables by itself on selected segments is only possible with group 4
- Parameters:
var (Var) – The target variable to set
value (int) – The absolute value to set
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static var_abs(var: Var, value: int) str ¶
Generate a command that sets a variable absolute.
- Parameters:
var (Var) – The target variable to set
value (int) – The absolute value to set
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static var_rel(var: Var, rel_var_ref: RelVarRef, value: int, software_serial: int) str ¶
Generate a command to change the value of a variable.
- Parameters:
- Returns:
The PCK command (without address header) as text
- Return type:
str
- static var_reset(var: Var, software_serial: int) str ¶
Generate a command that resets a variable to 0.
- Parameters:
var (Var) – The target variable to set 0
software_serial (int) – The expected firmware version of all receiving modules.
- Returns:
The PCK command (without address header) as text
- Return type:
str
- class pypck.pck_commands.PckParser¶
Helpers to parse LCN-PCK commands.
LCN-PCK is the command-syntax used by LCN-PCHK to send and receive LCN commands.
- static get_boolean_value(input_byte: int) list[bool] ¶
Get boolean representation for the given byte.
- Parameters:
input_byte (int) – Input byte as int8.
- Returns:
List with 8 boolean values.
- Return type:
list