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 busport (
int) – port of the PaSD buspolling_rate (
float) – minimum amount of time between communications on the PaSD busdevice_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 failureattribute_read_delay (
float) – time in seconds to wait after writing an attribute before reading it againport_status_read_delay (
float) – time in seconds to wait after setting port status before reading it againport_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 usecommunication_state_callback (
Callable[[CommunicationStatus],None]) – callback to be called when the status of the communications channel between the component manager and its component changescomponent_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 loggingpymodbus_log_dir (
Optional[str]) – optional directory path for pymodbus logging
- abort(task_callback=None)
Abort all delayed requests in the PaSD bus request provider.
- 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:
- 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:
- 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:
- initialize_smartbox(smartbox_id)
Initialize a smartbox by writing to its status register.
- Param:
smartbox_id: id of the smartbox being addressed
- Return type:
- 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:
- 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:
- 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:
- 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.
- 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:
- 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:
- 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:
- reset_smartbox_alarms(smartbox_id)
Reset a smartbox alarms register.
- reset_smartbox_port_breaker(smartbox_id, port_number)
Reset a smartbox port’s breaker.
- reset_smartbox_warnings(smartbox_id)
Reset a smartbox warnings register.
- set_fndh_led_pattern(pattern)
Set the FNDH’s LED pattern.
- set_fndh_low_pass_filters(cutoff, extra_sensors=False)
Set the FNDH’s sensors’ low pass filter constants.
- set_fndh_port_powers(port_powers, stay_on_when_offline)
Set the FNDH port powers.
- Parameters:
- Return type:
- set_smartbox_led_pattern(smartbox_id, pattern)
Set a smartbox’s LED pattern.
- set_smartbox_low_pass_filters(smartbox_id, cutoff, extra_sensors=False)
Set the Smartbox’s sensors’ low pass filter constants.
- 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:
- 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:
- update_port_power_states(port_power_states)
Update the port power states and therefore the list of smartboxes to poll.
- 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)