PaSD bus component manager

This module implements a component manager for a PaSD bus.

class PasdBusComponentManager(host, port, polling_rate, device_polling_rate, poll_delay_after_failure, attribute_read_delay, port_status_read_delay, port_power_delay, smartbox_startup_delay, timeout, logger, communication_state_callback, component_state_callback, pasd_device_state_callback, smartbox_ids, enable_pymodbus_logging, pymodbus_log_dir)

A component manager for a PaSD bus.

__init__(host, port, polling_rate, device_polling_rate, poll_delay_after_failure, attribute_read_delay, port_status_read_delay, port_power_delay, smartbox_startup_delay, timeout, logger, communication_state_callback, component_state_callback, pasd_device_state_callback, smartbox_ids, enable_pymodbus_logging, pymodbus_log_dir)

Initialise a new instance.

Parameters:
  • host (str) – IP address of PaSD bus

  • port (int) – port of the PaSD bus

  • polling_rate (float) – minimum amount of time between communications on the PaSD bus

  • device_polling_rate (float) – minimum amount of time between communications with the same device.

  • poll_delay_after_failure (float) – time in seconds to wait before next poll after a comms failure

  • attribute_read_delay (float) – time in seconds to wait after writing an attribute before reading it again

  • port_status_read_delay (float) – time in seconds to wait after setting port status before reading it again

  • port_power_delay (float) – time in seconds to wait between setting each FNDH port power.

  • smartbox_startup_delay (float) – time in seconds to wait after a smartbox is powered on before starting to poll it.

  • timeout (float) – maximum time to wait for a response to a server request (in seconds).

  • logger (Logger) – a logger for this object to use

  • communication_state_callback (Callable[[CommunicationStatus], None]) – callback to be called when the status of the communications channel between the component manager and its component changes

  • component_state_callback (Callable[..., None]) – callback to be called when the component state changes. Note this in this case the “component” is the PaSD bus itself. The PaSD bus has no no monitoring points. All we can do is infer that it is powered on and not in fault, from the fact that we receive responses to our requests.

  • pasd_device_state_callback (Callable[..., None]) – callback to be called when one of the PaSD devices (i.e. the FNDH or one of the smartboxes) provides updated information about its state. This callable takes a single positional argument, which is the device number, and keyword arguments representing the state changes.

  • smartbox_ids (list[int]) – list of smartbox IDs associated with each FNDH port.

  • enable_pymodbus_logging (bool) – whether to enable pymodbus logging

  • pymodbus_log_dir (Optional[str]) – optional directory path for pymodbus logging

abort(task_callback=None)

Abort all delayed requests in the PaSD bus request provider.

Parameters:

task_callback (Optional[Callable]) – notified of task progress.

Return type:

tuple[TaskStatus, str]

Returns:

tuple of TaskStatus and message.

cleanup()

Delete and clean up any remaining processes.

Return type:

None

get_request()

Return the action/s to be taken in the next poll.

Raises:

AssertionError – if an unrecognised poll option is returned by the provider

Return type:

Optional[PasdBusRequest]

Returns:

attributes to be read and commands to be executed in the next poll.

initialize_fem_current_trip_thresholds(smartbox_id, fem_current_trip_threshold)

Initialize the FEM current trip thresholds.

Param:

smartbox_id: id of the smartbox being addressed

Param:

fem_current_trip_threshold: threshold value to write

Return type:

None

initialize_fndh()

Initialize the FNDH by writing to its status register.

Return type:

None

initialize_sb_input_voltage_thresholds(smartbox_id, input_voltage_thresholds)

Initialize the input voltage thresholds.

Param:

smartbox_id: id of the smartbox being addressed

Param:

input_voltage_thresholds: alarm hi, warn hi, warn lo, alarm lo values

Return type:

None

initialize_smartbox(smartbox_id)

Initialize a smartbox by writing to its status register.

Param:

smartbox_id: id of the smartbox being addressed

Return type:

None

off(task_callback=None)

Turn off the PaSD bus simulator.

Parameters:

task_callback (Optional[Callable]) – callback to be called when the status of the command changes

Raises:

NotImplementedError – because this is not yet implemented.

Return type:

tuple[TaskStatus, str]

on(task_callback=None)

Turn on the PaSD bus simulator.

Parameters:

task_callback (Optional[Callable]) – callback to be called when the status of the command changes

Raises:

NotImplementedError – because this is not yet implemented.

Return type:

tuple[TaskStatus, str]

poll(poll_request)

Poll the PaSD hardware.

Connect to the hardware, execute a command or read some values.

Parameters:

poll_request (PasdBusRequest) – specification of the actions to be taken in this poll.

Return type:

PasdBusResponse

Returns:

responses to queries in this poll

poll_failed(exception)

Respond to an exception being raised by a poll attempt.

This is a hook called by the poller when an exception occurs.

Parameters:

exception (Exception) – the exception that was raised by a recent poll attempt.

Return type:

None

poll_succeeded(poll_response)

Handle the receipt of new polling values.

This is a hook called by the poller when values have been read during a poll.

Parameters:

poll_response (PasdBusResponse) – response to the pool, including any values read.

Return type:

None

polling_started()

Define actions to be taken when polling starts.

Return type:

None

polling_stopped()

Define actions to be taken when polling stops.

Return type:

None

request_startup_info(device_id)

Read the registers normally just polled at startup.

Param:

device_id: The id of the device being addressed

Return type:

None

request_status_read()

Read the FNPC status register to attempt to reset comms.

Return type:

None

reset(task_callback=None)

Reset the PaSD bus simulator.

Parameters:

task_callback (Optional[Callable]) – callback to be called when the status of the command changes

Raises:

NotImplementedError – because this is not yet implemented.

Return type:

tuple[TaskStatus, str]

reset_connection()

Reset the connection to the device.

Return type:

None

reset_fncc_status()

Reset the FNCC status register.

Return type:

None

reset_fndh_alarms()

Reset the FNDH alarms register.

Return type:

None

reset_fndh_warnings()

Reset the FNDH warnings register.

Return type:

None

reset_smartbox_alarms(smartbox_id)

Reset a smartbox alarms register.

Parameters:

smartbox_id (int) – the smartbox to have its alarms reset

Return type:

None

reset_smartbox_port_breaker(smartbox_id, port_number)

Reset a smartbox port’s breaker.

Parameters:
  • smartbox_id (int) – id of the smartbox being addressed.

  • port_number (int) – the number of the port to reset.

Return type:

None

reset_smartbox_warnings(smartbox_id)

Reset a smartbox warnings register.

Parameters:

smartbox_id (int) – the smartbox to have its warnings reset

Return type:

None

set_fndh_led_pattern(pattern)

Set the FNDH’s LED pattern.

Parameters:

pattern (str) – name of the service LED pattern.

Return type:

None

set_fndh_low_pass_filters(cutoff, extra_sensors=False)

Set the FNDH’s sensors’ low pass filter constants.

Parameters:
  • cutoff (float) – frequency of LPF to set.

  • extra_sensors (bool) – write the constant to the extra sensors’ registers after the LED status register.

Return type:

None

set_fndh_port_powers(port_powers, stay_on_when_offline)

Set the FNDH port powers.

Parameters:
  • port_powers (list[Optional[bool]]) – specification of the desired power of each port. True means on, False means off, None means no change desired.

  • stay_on_when_offline (bool) – whether any ports being turned on should remain on if MCCS loses its connection with the PaSD.

Return type:

None

set_smartbox_led_pattern(smartbox_id, pattern)

Set a smartbox’s LED pattern.

Parameters:
  • smartbox_id (int) – the smartbox to have its LEDs’ pattern set.

  • pattern (str) – name of the service LED pattern.

Return type:

None

set_smartbox_low_pass_filters(smartbox_id, cutoff, extra_sensors=False)

Set the Smartbox’s sensors’ low pass filter constants.

Parameters:
  • smartbox_id (int) – the smartbox to have its LPF constants set.

  • cutoff (float) – frequency of LPF to set.

  • extra_sensors (bool) – write the constant to the extra sensors’ registers after the LED status register.

Return type:

None

set_smartbox_port_powers(smartbox_id, port_powers, stay_on_when_offline)

Set the smartbox’s port powers.

Parameters:
  • smartbox_id (int) – id of the smartbox being addressed.

  • port_powers (list[Optional[bool]]) – specification of the desired power of each port. True means on, False means off, None means no change desired.

  • stay_on_when_offline (bool) – whether any ports being turned on should remain on if MCCS loses its connection with the PaSD.

Return type:

None

standby(task_callback=None)

Put the PaSD bus simulator into low-power standby mode.

Parameters:

task_callback (Optional[Callable]) – callback to be called when the status of the command changes

Raises:

NotImplementedError – because this is not yet implemented.

Return type:

tuple[TaskStatus, str]

update_port_power_states(port_power_states)

Update the port power states and therefore the list of smartboxes to poll.

Parameters:

port_power_states (list[bool]) – list of port power statuses (true=On, false=Off).

Return type:

None

write_attribute(device_id, attribute_name, value)

Write a new value to an attribute.

Parameters:
  • device_id (int) – the smartbox or FNDH id

  • attribute_name (str) – the name of the attribute to write

  • value (Any) – the new value to write

Return type:

None

class PasdBusRequest(device_id, command, attribute_to_write, arguments)

Class representing an action to be performed by a poll.

it comprises a device ID number, a command name or attribute to write, and a list of command arguments or values

If the command name and attribute_to_write are both None, then the arguments are interpreted as a list of attribute values to read.

__init__(device_id, command, attribute_to_write, arguments)
class PasdBusResponse(device_id, command, data)

Class representing the result of a poll.

It comprises the device ID number, a command name, and a dictionary of returned data.

If the command name is None, then the request was an attribute read request, and the data are the attribute values. Otherwise, the data is the result of executing the command

__init__(device_id, command, data)