Health

This module implements infrastructure for health management.

class HealthModel(health_changed_callback, **kwargs)

A simple health model the supports.

  • HealthState.UNKNOWN – when communication with the component is not established.

  • HealthState.FAILED – when the component has faulted

  • HealthState.OK – when neither of the above conditions holds.

This health model does not support HealthState.DEGRADED. It is up to subclasses to implement support for DEGRADED if required.

__init__(health_changed_callback, **kwargs)

Initialise a new instance.

Parameters:
  • health_changed_callback (Callable[..., None]) – callback to be called whenever there is a change to this this health model’s evaluated health state.

  • kwargs (Any) – additional keyword arguments specifying initial values for state.

component_fault(fault)

Handle a component experiencing or recovering from a fault.

This is a callback hook that is called when the component goes into or out of FAULT state.

Parameters:

fault (bool) – whether the component has faulted or not

Return type:

None

evaluate_health()

Re-evaluate the health state.

This method contains the logic for evaluating the health. It is this method that should be extended by subclasses in order to define how health is evaluated by their particular device.

Return type:

HealthState

Returns:

the new health state.

property health_params: dict[str, float]

Get the thresholds for health rules.

Returns:

the thresholds for health rules

property health_state: HealthState

Return the health state.

Returns:

the health state.

is_communicating(communicating)

Handle change in communication with the component.

Parameters:

communicating (bool) – whether communications with the component is established.

Return type:

None

update_health()

Update health state.

This method calls the :py:meth:evaluate_health method to figure out what the new health state should be, and then updates the health_state attribute, calling the callback if required.

Return type:

None

update_state(**kwargs)

Update this health model with state relevant to evaluating health.

Parameters:

kwargs (Any) – updated state

Return type:

None