pciprotocol Module

class cbus.protocol.pciprotocol.PCIProtocol(timesync_frequency: int = 10, handle_clock_requests: bool = True, connection_lost_future: Optional[_asyncio.Future] = None)

Bases: cbus.protocol.cbus_protocol.CBusProtocol

Implements an asyncio Protocol for communicating with a C-Bus PCI/CNI over TCP or serial.

clock_datetime(when: Optional[datetime.datetime] = None)

Sends the system’s local time to the CBus network.

Parameters:when (datetime.datetime) – The time and date to send to the CBus network. Defaults to current local time.
connection_lost(exc: Optional[Exception]) → None

Called when the connection is lost or closed.

The argument is an exception object or None (the latter meaning a regular EOF is received or the connection was aborted or closed).

connection_made(transport: asyncio.transports.WriteTransport) → None

Called by asyncio when a connection is made to the PCI. This will perform a reset of the PCI to establish the correct communications protocol, and start time synchronisation.

handle_cbus_packet(p: cbus.protocol.base_packet.BasePacket) → None

Dispatches all packet types into a high level event handler.

identify(unit_address, attribute)

Sends an IDENTIFY command to the given unit_address.

Parameters:
  • unit_address (int) – Unit address to send the packet to
  • attribute (int) – Attribute ID to retrieve information for. See s7.2 of Serial Interface Guide for acceptable codes.
Returns:

Single-byte string with code for the confirmation event.

Return type:

string

lighting_group_off(group_addr: Union[int, Iterable[int]])

Turns off the lights for the given group_id.

Parameters:group_addr (int, or iterable of ints of length <= 9.) – Group address(es) to turn the lights off for, up to 9
Returns:Single-byte string with code for the confirmation event.
Return type:string
lighting_group_on(group_addr: Union[int, Iterable[int]])

Turns on the lights for the given group_id.

Parameters:group_addr (int, or iterable of ints of length <= 9.) – Group address(es) to turn the lights on for, up to 9
Returns:Single-byte string with code for the confirmation event.
Return type:string
lighting_group_ramp(group_addr: int, duration: int, level: int = 255)

Ramps (fades) a group address to a specified lighting level.

Note: CBus only supports a limited number of fade durations, in decreasing accuracy up to 17 minutes (1020 seconds). Durations longer than this will throw an error.

A duration of 0 will ramp “instantly” to the given level.

Parameters:
  • group_addr (int) – The group address to ramp.
  • duration (int) – Duration, in seconds, that the ramp should occur over.
  • level (int) – A value between 0 and 255 indicating the brightness.
Returns:

Single-byte string with code for the confirmation event.

Return type:

string

lighting_group_terminate_ramp(group_addr: Union[int, Iterable[int]])

Stops ramping a group address at the current point.

Parameters:group_addr (int) – Group address to stop ramping of.
Returns:Single-byte string with code for the confirmation event.
Return type:string
on_clock_request(source_addr)

Event called when a unit requests time from the network.

Parameters:source_addr (int) – Source address of the unit requesting time.
on_clock_update(source_addr, val)

Event called when a unit sends time to the network.

Parameters:source_addr (int) – Source address of the unit requesting time.
on_confirmation(code: bytes, success: bool)

Event called when a command confirmation event was received.

Parameters:
  • code – A single byte matching the command that this is a response to.
  • success – True if the command was successful, False otherwise.
on_lighting_group_off(source_addr: int, group_addr: int)

Event called when a lighting application “off” request is received.

Parameters:
  • source_addr (int) – Source address of the unit that generated this event.
  • group_addr (int) – Group address being turned off.
on_lighting_group_on(source_addr: int, group_addr: int)

Event called when a lighting application “on” request is received.

Parameters:
  • source_addr (int) – Source address of the unit that generated this event.
  • group_addr (int) – Group address being turned on.
on_lighting_group_ramp(source_addr: int, group_addr: int, duration: int, level: int)

Event called when a lighting application ramp (fade) request is received.

Parameters:
  • source_addr (int) – Source address of the unit that generated this event.
  • group_addr (int) – Group address being ramped.
  • duration (int) – Duration, in seconds, that the ramp is occurring over.
  • level (int) – Target brightness of the ramp (0 - 255).
on_lighting_group_terminate_ramp(source_addr: int, group_addr: int)

Event called when a lighting application “terminate ramp” request is received.

Parameters:
  • source_addr (int) – Source address of the unit that generated this event.
  • group_addr (int) – Group address stopping ramping.
on_lighting_label_text(source_addr: int, group_addr: int, flavour: int, language_code: int, label: str)

Event called when a group address’ label text is updated.

Parameters:
  • source_addr (int) – Source address of the unit that generated this event.
  • group_addr (int) – Group address to relabel.
  • flavour (int) – “Flavour” of the label to update. This is a value between 0 and 3.
  • language_code (int) – Language code for the label.
  • label (str) – Label text, or an empty string to delete the label.
on_mmi(application: int, data: bytes)

Event called when a MMI was received.

Parameters:
  • application – Application that this MMI concerns.
  • data – MMI data
on_pci_cannot_accept_data()

Event called whenever the PCI cannot accept the supplied data. Common reasons for this occurring:

  • The checksum is incorrect.
  • The buffer in the PCI is full.

Unfortunately the PCI does not tell us which requests these are associated with.

This error can occur if data is being sent to the PCI too quickly, or if the cable connecting the PCI to the computer is faulty.

While the PCI can operate at 9600 baud, this only applies to data it sends, not to data it recieves.

on_pci_power_up()

If Power-up Notification (PUN) is enabled on the PCI, this event is fired.

This event may be fired multiple times in quick succession, as the PCI will send the event twice.

on_reset()

Event called when the PCI has been hard reset.

pci_reset()

Performs a full reset of the PCI.

timesync()