Attribute Polling Component Manager

This module implements a generic attribute polling component manager.

class AttrInfo(attr_args, polling_period)

Base class for dynamic attribute metadata.

Parameters:
  • attr_args (dict[str, Any]) – kwargs that will be passed to PyTango’s tango.server.attribute() function.

  • polling_period (float) – the minimum time in seconds between successive hardware reads for this attribute.

__init__(attr_args, polling_period)
class AttrPollRequest(writes, reads)

Helper class to hold read/write requests passed to the poller.

__init__(writes, reads)
class AttributePollingComponentManager(logger, communication_state_callback, component_state_callback, attributes, poll_rate)

An implementation of the attribute polling component manager.

__init__(logger, communication_state_callback, component_state_callback, attributes, poll_rate)
enqueue_write(attr_name, val)

Queue an attribute value to be written on the next poll.

If there is already a write pending for the attribute, it will be superseded.

Parameters:
  • attr_name (str) – the name of the attribute to be written

  • val (Any) – the attribute value to write

Return type:

None

from_python(attr_name, val)

Convert from raw Python type to a hardware-compatible type.

This is called in enqueue_write() so that any conversion error happens early, when an attribute is set, rather than in the polling thread.

Parameters:
  • attr_name (str) – the name of the attribute to be written

  • val (Any) – the attribute value to write in snmp type

Return type:

Any

Returns:

the value as an snmp data type

get_request()

Assemble a list of ObjectTypes representing pending writes and reads.

The writes appear first, and come from self._pending_writes. Reads are requested for each attribute whose last successful poll happened longer ago than its polling period and the polling period is not zero, and each attribute being written.

Return type:

AttrPollRequest

Returns:

a list of attributes that should be polled next.

poll(poll_request)

Group by writes and reads, chunk, and run the appropriate SNMP command.

Aggregate any returned ObjectTypes from GET commands as the poll response.

Parameters:

poll_request (AttrPollRequest) – group of read & write attribute requests to poll

Raises:

NotImplementedError – up to the subclass

Return type:

dict[str, Any]

poll_failed(exception)

Set PowerState.UNKNOWN when polling fails.

This is a bug fix that should be upstreamed to ska-tango-base once we are confident it works.

Parameters:

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

Return type:

None

poll_succeeded(poll_response)

Notify the device of the return values of a successful poll.

This involves type coercion from PySNMP- to PyTango-compatible types.

Parameters:

poll_response (dict[str, Any]) – the snmp response

Return type:

None