Upstream Component Manager

This module contains classes for interacting with upstream devices.

class PowerSupplyProxySimulator(logger, communication_state_callback, component_state_callback, initial_power_state=PowerState.OFF, initial_fail=False, _simulator=None)

A component manager that simulates a proxy to an upstream power supply device.

MCCS manages numerous hardware devices that can’t turn turn themselves off and on directly. Rather, in order for a tango device to turn its hardware off or on, it needs to contact the tango device for an upstream device that supplies power to the hardware, and tell that tango device to supply/deny power to the hardware.

However this functionality is largely not implemented yet, so we need to “fake” it. Plus, even when it _is_ implemented, there will be a need to simulate this when in simulation mode. This class provides that simulation pattern.

__init__(logger, communication_state_callback, component_state_callback, initial_power_state=PowerState.OFF, initial_fail=False, _simulator=None)

Initialise a new instance.

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

  • communication_state_callback (Optional[Callable]) – callback to be called when the status of communications between the component manager and its component changes.

  • component_state_callback (Optional[Callable]) – callback to be called when the state of the component changes.

  • initial_power_state (PowerState) – the initial power state of the simulated power supply

  • initial_fail (bool) – the initial failure condition of the simulated power supply. If True, the power supply will immediately simulate failure.

abort_commands(task_callback=None)

Abort all queued tasks.

This implementation does not abort tasks that have already been picked up and executed by the poller.

Parameters:

task_callback (Optional[Callable]) – callback to be called whenever the status of the task changes.

Return type:

tuple[TaskStatus, str]

Returns:

a task status and message.

get_request()

Return the reads and writes to be executed in the next poll.

In this implementation, this simply returns an optional boolean that indicates whether or not to turn the power supply on or off. If true, we are asking to turn on the power supply; if false, we are asking to turn off the power supply; if None, we aren’t asking for any action to be taken.

Return type:

tuple[Optional[bool]]

Returns:

reads and writes to be executed in the next poll.

off(task_callback=None)

Turn the power supply off.

Parameters:

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

Return type:

tuple[TaskStatus, str]

Returns:

task status and message

on(task_callback=None)

Turn the power supply on.

Parameters:

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

Return type:

tuple[TaskStatus, str]

Returns:

task status and message

poll(poll_request)

Poll the power supply.

Parameters:

poll_request (tuple[Optional[bool]]) – specification of the reads and writes to be performed in this poll. In this implementation, this is simply an optional boolean that indicates whether or not to turn the power supply on or off. If True, this poll will turn on the power supply; if False, this poll will turn off the power supply; if None, no action will be taken.

Return type:

PowerState

Returns:

responses to queries in this poll. In this implementation, this is simply a boolean that tells whether the power supply is on. If True, the power supply is currently on. If False, it is currently off.

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 a successful poll, including any values received.

This is a hook called by the poller at the end of each successful poll.

Parameters:

poll_response (PowerState) – response to the poll, including any values received. In this implementation, this is simply a boolean indicating whether the power supply is on or not.

Return type:

None

reset(task_callback=None)

Reset the component.

Parameters:

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

Raises:

NotImplementedError – because reset has not been implemented yet

Return type:

tuple[TaskStatus, str]

standby(task_callback=None)

Raise an error indicating that standby mode is not supported.

Parameters:

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

Raises:

NotImplementedError – because this simulator does not support standby mode.

Return type:

tuple[TaskStatus, str]

class PowerSupplySimulator(initial_power_state=PowerState.OFF, initial_fail=False, time_to_return=0.05, time_to_complete=0.4)

A power supply simulator for the component manager to manage.

It supports the four power states:

  • NO_SUPPLY means the power supply is itself unsupplied with power, so it cannot be communicated with, and hence cannot service the off() or on() commands.

  • UNKNOWN means the power supply is supplied with power, but communication with it has not been established. Again, the power supply cannot service off or on commands.

  • OFF means the power supply is supplied with power, and therefore able to supply power. However it is currently not supplying power. Communication with the power supply is established, so it can accept an on command.

  • ON means the power supply is supplied with power, and is therefore able to supply power, and indeed is currently doing so. Communication with the power supply is established, so it can accept an off command.

The main commands are off and on, which simulate time-consuming operations on the power supply; and a general simulate_power command which causes the power supply to “spontaneously” change to a new power state.

__init__(initial_power_state=PowerState.OFF, initial_fail=False, time_to_return=0.05, time_to_complete=0.4)

Initialise a new instance.

Parameters:
  • initial_power_state (PowerState) – the initial power state of this simulator.

  • initial_fail (bool) – whether to enter a simulated failure state.

  • time_to_return (float) – the amount of time to delay before returning from a command method. This simulates unavoidable communications latency.

  • time_to_complete (float) – the amount of time to delay before the component state reflects actions taken on it. This simulates hardware processing delay.

off()

Deny power to the downstream device.

Return type:

None

on()

Supply power to the downstream device.

Return type:

None

property power_state: PowerState

Return whether the power supply is on or not.

Raises:

ValueError – if simulating failure.

Returns:

the power state of the simulated power supply.

simulate_failure(fail)

Simulate, or stop simulating, power supply failure.

When simulating failure, any attempt to read the power_state property will raise an exception.

Parameters:

fail (bool) – whether to simulate failure.

Return type:

None

simulate_power(power_state)

Simulate a specific power state.

Parameters:

power_state (PowerState) – the new power state.

Return type:

None