# `pypck.module`

Module and group classes.

class pypck.module.AbstractConnection(conn: PchkConnectionManager, addr: LcnAddr, software_serial: int | None = None, wants_ack: bool = False)

  Organizes communication with a specific module.

  Sends status requests to the connection and handles status responses.

  async activate_scene(register_id: int, scene_id: int, output_ports: Sequence[OutputPort] = (), relay_ports: Sequence[RelayPort] = (), ramp: int | None = None) → bool

    Activate the stored states for the given scene.

    Parameters:

      - register_id (int) – Register id 0..9

      - scene_id (int) – Scene id 0..9

      - output_ports (list(OutputPort)) – Output ports to activate as list

      - relay_ports (list(RelayPort)) – Relay ports to activate as list

      - ramp (int) – Ramp value

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  property addr_id: int

    Get the module or group id.

  async beep(sound: BeepSound, count: int) → bool

    Send a command to make count number of beep sounds.

    Parameters:

      - sound (BeepSound) – Beep sound style

      - count (int) – Number of beeps (1..15)

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  async clear_dyn_text(row_id: int) → bool

    Clear previously sent dynamic text.

    Parameters:

      row_id (int) – Row id 0..3

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  async control_led(led: LedPort, state: LedStatus) → bool

    Send a command to control a led.

    Parameters:

      - led (LedPort) – Led port

      - state (LedStatus) – Led status

  async control_motors_outputs(state: MotorStateModifier, reverse_time: MotorReverseTime | None = None) → bool

    Send a command to control a motor via output ports 1+2.

    Parameters:

      - state (MotorStateModifier) – The modifier for the cover state

      - reverse_time (MotorReverseTime) – Reverse time for modules with FW<190C

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  async control_motors_relays(states: list[MotorStateModifier]) → bool

    Send a command to control motors via relays.

    Parameters:

      states (list(:class: ~pypck.lcn-defs.MotorStateModifier)) – The 4 modifiers for the cover states as a list

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  async control_relays(states: list[RelayStateModifier]) → bool

    Send a command to control relays.

    Parameters:

      states (list(`RelayStateModifier`)) – The 8 modifiers for the relay states as alist

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  async control_relays_timer(time_msec: int, states: list[RelayStateModifier]) → bool

    Send a command to control relays.

    Parameters:

      - time_msec (int) – Duration of timer in milliseconds

      - states (list(`RelayStateModifier`)) – The 8 modifiers for the relay states as alist

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  async dim_all_outputs(percent: float, ramp: int, software_serial: int | None = None) → bool

    Send a dim command for all output-ports.

    Parameters:

      - percent (float) – Brightness in percent 0..100

      - ramp (int) – Ramp time in milliseconds.

      - software_serial (int) – The minimum firmware version expected by any receiving module.

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  async dim_output(output_id: int, percent: float, ramp: int) → bool

    Send 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 time in milliseconds

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  async dyn_text(row_id: int, text: str) → bool

    Send dynamic text to a module.

    Parameters:

      - row_id (int) – Row id 0..3

      - text (str) – Text to send (up to 60 bytes)

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  property hardware_serial: int

    Get the hardware serial number.

  property hardware_type: HardwareType

    Get the hardware type.

  property is_group: int

    Return whether this connection refers to a module or group.

  async lock_keys(table_id: int, states: list[KeyLockStateModifier]) → bool

    Send a command to lock keys.

    Parameters:

      - table_id (int) – Table id: 0..3

      - states (keyLockStateModifier) – The 8 modifiers for the key lock states as a list

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  async lock_keys_tab_a_temporary(delay_time: int, delay_unit: TimeUnit, states: list[bool]) → bool

    Send a command to lock keys in table A temporary.

    Parameters:

      - delay_time (int) – Time to lock keys

      - delay_unit (TimeUnit) – Unit of time

      - states (list(bool)) – The 8 lock states of the keys as list (locked=True, unlocked=False)

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  async lock_regulator(reg_id: int, state: bool, target_value: float = -1) → bool

    Send a command to lock a regulator.

    Parameters:

      - reg_id (int) – Regulator id

      - state (bool) – Lock state (locked=True, unlocked=False)

      - target_value (float) – Target value in percent (use -1 to ignore)

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  property manu: int

    Get the manufacturing number.

  async pck(pck: str) → bool

    Send arbitrary PCK command.

    Parameters:

      pck (str) – PCK command

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  async ping() → bool

    Send a command that does nothing and request an acknowledgement.

  async rel_output(output_id: int, percent: float) → bool

    Send a command to change the value of an output-port.

    Parameters:

      - output_id (int) – Output id 0..3

      - percent (float) – Relative brightness in percent -100..100

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  async request_serials() → dict[str, int | HardwareType]

    Request module serials.

  property seg_id: int

    Get the segment id.

  async send_command(wants_ack: bool, pck: str | bytes) → bool

    Send a command to the module represented by this class.

    Parameters:

      - wants_ack (bool) – Also send a request for acknowledge.

      - pck (str) – PCK command (without header).

  async send_keys(keys: list[list[bool]], cmd: SendKeyCommand) → list[bool]

    Send a command to send keys.

    Parameters:

      - keys (list(bool)[4][8]) – 2d-list with [table_id][key_id] bool values, if command should be sent to specific key

      - cmd (SendKeyCommand) – command to send for each table

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      list of bool

  async send_keys_hit_deferred(keys: list[list[bool]], delay_time: int, delay_unit: TimeUnit) → list[bool]

    Send a command to send keys deferred.

    Parameters:

      - keys (list(bool)[4][8]) – 2d-list with [table_id][key_id] bool values, if command should be sent to specific key

      - delay_time (int) – Delay time

      - delay_unit (TimeUnit) – Unit of time

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      list of bool

  property serial_known: Awaitable[bool]

    Check if serials have already been received from module.

  property serials: dict[str, int | HardwareType]

    Return serial numbers of a module.

  property software_serial: int

    Get the software serial number.

  async store_scene(register_id: int, scene_id: int, output_ports: Sequence[OutputPort] = (), relay_ports: Sequence[RelayPort] = (), ramp: int | None = None) → bool

    Store states in the given scene.

    Parameters:

      - register_id (int) – Register id 0..9

      - scene_id (int) – Scene id 0..9

      - output_ports (list(OutputPort)) – Output ports to store as list

      - relay_ports (list(RelayPort)) – Relay ports to store as list

      - ramp (int) – Ramp value

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  async store_scene_outputs_direct(register_id: int, scene_id: int, percents: Sequence[float], ramps: Sequence[int]) → bool

    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:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  property task_registry: TaskRegistry

    Get the task registry.

  async toggle_all_outputs(ramp: int) → bool

    Generate a command that toggles all output-ports.

    Toggle Mode: (on->off, off->on).

    Parameters:

      ramp (int) – Ramp time in milliseconds

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  async toggle_output(output_id: int, ramp: int) → bool

    Send 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 time in milliseconds

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  async var_abs(var: Var, value: float | VarValue, unit: VarUnit = VarUnit.NATIVE, software_serial: int | None = None) → bool

    Send a command to set the absolute value to a variable.

    Parameters:

      - var (Var) – Variable

      - value (float) – Absolute value to set

      - unit (VarUnit) – Unit of variable

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  async var_rel(var: Var, value: float | VarValue, unit: VarUnit = VarUnit.NATIVE, value_ref: RelVarRef = RelVarRef.CURRENT, software_serial: int | None = None) → bool

    Send a command to change the value of a variable.

    Parameters:

      - var (Var) – Variable

      - value (float) – Relative value to add (may also be negative)

      - unit (VarUnit) – Unit of variable

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

  async var_reset(var: Var, software_serial: int | None = None) → bool

    Send a command to reset the variable value.

    Parameters:

      var (Var) – Variable

    Returns:

      True if command was sent successfully, False otherwise

    Return type:

      bool

class pypck.module.GroupConnection(conn: PchkConnectionManager, addr: LcnAddr, software_serial: int = 1507846)

  Organizes communication with a specific group.

  It is assumed that all modules within this group are newer than FW170206

  async activate_status_request_handler(item: Any) → None

    Activate a specific TimeoutRetryHandler for status requests.

  async activate_status_request_handlers() → None

    Activate all TimeoutRetryHandlers for status requests.

  async var_abs(var: Var, value: float | VarValue, unit: VarUnit = VarUnit.NATIVE, software_serial: int | None = None) → bool

    Send a command to set the absolute value to a variable.

    Parameters:

      - var (Var) – Variable

      - value (float) – Absolute value to set

      - unit (VarUnit) – Unit of variable

  async var_rel(var: Var, value: float | VarValue, unit: VarUnit = VarUnit.NATIVE, value_ref: RelVarRef = RelVarRef.CURRENT, software_serial: int | None = None) → bool

    Send a command to change the value of a variable.

    Parameters:

      - var (Var) – Variable

      - value (float) – Relative value to add (may also be negative)

      - unit (VarUnit) – Unit of variable

  async var_reset(var: Var, software_serial: int | None = None) → bool

    Send a command to reset the variable value.

    Parameters:

      var (Var) – Variable

class pypck.module.ModuleConnection(conn: PchkConnectionManager, addr: LcnAddr, activate_status_requests: bool = False, has_s0_enabled: bool = False, software_serial: int | None = None, wants_ack: bool = True)

  Organizes communication with a specific module or group.

  async activate_status_request_handler(item: Any) → None

    Activate a specific TimeoutRetryHandler for status requests.

  async activate_status_request_handlers() → None

    Activate all TimeoutRetryHandlers for status requests.

  async async_process_input(inp: Input) → None

    Is called by input object’s process method.

    Method to handle incoming commands for this specific module (status, toggle_output, switch_relays, …)

  async cancel_requests() → None

    Cancel all TimeoutRetryHandlers.

  async cancel_status_request_handler(item: Any) → None

    Cancel a specific TimeoutRetryHandler for status requests.

  async cancel_status_request_handlers() → None

    Canecl all TimeoutRetryHandlers for status requests.

  property comment: str

    Return stored comments.

  dump_details() → dict[str, Any]

    Dump detailed information about this module.

  property dynamic_groups: set[LcnAddr]

    Return dynamic group membership.

  get_s0_enabled() → bool

    Get the activation status for S0 variables.

  property groups: set[LcnAddr]

    Return static and dynamic group membership.

  property name: str

    Return stored name.

  property oem_text: list[str]

    Return stored OEM text.

  async on_ack(code: int = -1) → None

    Is called whenever an acknowledge is received from the LCN module.

    Parameters:

      code (int) – The LCN internal code. -1 means “positive” acknowledge

  register_for_inputs(callback: Callable[[Input], None]) → Callable[[...], None]

    Register a function for callback on PCK message received.

    Returns a function to unregister the callback.

  async request_comment() → str

    Request comments from a module.

  async request_dynamic_groups() → set[LcnAddr]

    Request module dynamic group memberships.

  async request_groups() → set[LcnAddr]

    Request module group memberships.

  async request_name() → str

    Request module name.

  async request_oem_text() → list[str]

    Request OEM text from a module.

  async request_serials() → dict[str, int | HardwareType]

    Request module serials.

  async request_static_groups() → set[LcnAddr]

    Request module static group memberships.

  async send_command(wants_ack: bool, pck: str | bytes) → bool

    Send a command to the module represented by this class.

    Parameters:

      - wants_ack (bool) – Also send a request for acknowledge.

      - pck (str) – PCK command (without header).

  async send_command_with_ack(pck: str | bytes) → bool

    Send a PCK command and ensure receiving of an acknowledgement.

    Resends the PCK command if no acknowledgement has been received within timeout.

    Parameters:

      pck (str) – PCK command (without header).

    Returns:

      True if acknowledge was received, False otherwise

    Return type:

      bool

  property serial_known: Awaitable[bool]

    Check if serials have already been received from module.

  property serials: dict[str, int | HardwareType]

    Return serials number information.

  set_s0_enabled(s0_enabled: bool) → None

    Set the activation status for S0 variables.

    Parameters:

      s0_enabled (bool) – If True, a BU4L has to be connected to the hardware module and S0 mode has to be activated in LCN-PRO.

  property static_groups: set[LcnAddr]

    Return static group membership.