Device Proxy

This module implements a base device proxy for Sat LMC devices.

class SatDeviceProxy(fqdn, logger, connect=True, pass_through=True)

This class implements a base device proxy for Sat LMC devices.

At present it supports:

  • deferred connection: we can create the proxy without immediately trying to connect to the proxied device.

  • a :py:meth:connect method, for establishing that connection later

  • a :py:meth:check_initialised method, for checking that / waiting until the proxied device has transitioned out of INIT state.

  • Ability to subscribe to change events via the :py:meth:add_change_event_callback method.

__init__(fqdn, logger, connect=True, pass_through=True)

Create a new instance.

Parameters:
  • fqdn (str) – fqdn of the device to be proxied

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

  • connect (bool) – whether to connect immediately to the device. If False, then the device may be connected later by calling the connect() method.

  • pass_through (bool) – whether to pass unrecognised attribute accesses through to the underlying connection. Defaults to True but this will likely change in future once our proxies are more mature.

add_change_event_callback(attribute_name, callback, stateless=True)

Register a callback for change events being pushed by the device.

Parameters:
  • attribute_name (str) – the name of the attribute for which change events are subscribed.

  • callback (Callable[[str, Any, AttrQuality], None]) – the function to be called when a change event arrives.

  • stateless (bool) – whether to use Tango’s stateless subscription feature

Return type:

None

check_initialised(max_time=120.0)

Check that the device has completed initialisation.

That is, check that the device is no longer in state INIT.

Parameters:

max_time (float) – the (optional) maximum time, in seconds, to wait for the device to complete initialisation. The default is 120.0 i.e. two minutes. If set to 0 or None, the device is checked once and the call returns immediately.

Return type:

bool

Returns:

whether the device is initialised yet

connect(max_time=120.0)

Establish a connection to the device that we want to proxy.

Parameters:

max_time (float) – the maximum time, in seconds, to wait for a connection to be established. The default is 120 i.e. two minutes. If set to 0 or None, a single connection attempt is made, and the call returns immediately.

Return type:

None

classmethod set_default_connection_factory(connection_factory)

Set the default connection factory for this class.

This is super useful for unit testing: we can mock out tango.DeviceProxy altogether, by simply setting this class’s default connection factory to a mock factory.

Parameters:

connection_factory (Callable[[str], DeviceProxy]) – default factory to use to establish a connection to the device

Return type:

None