Skip to content
Snippets Groups Projects

Improving event subscription interface

Merged Jan David Mol requested to merge enhance-event-subscription-api into master
Files
8
# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy)
# SPDX-License-Identifier: Apache-2.0
from typing import Dict
import numpy
from tangostationcontrol.common.case_insensitive_string import CaseInsensitiveString
from tangostationcontrol.common.case_insensitive_dict import CaseInsensitiveDict
from tango.server import Device
@@ -17,7 +17,15 @@ class ChangeEvents:
def __init__(self, device: Device):
self.device = device
self.prev_values: Dict[str, object] = {}
# keep track of which attributes we manage
self.attributes: list[CaseInsensitiveString] = []
# previous values of attributes, to avoid
# emitting CHANGE_EVENTs when nothing changed.
self.prev_values: CaseInsensitiveDict[str, object] = {}
def is_configured(self, attr_name: str) -> bool:
return attr_name in self.attributes
def configure_attribute(self, attr_name: str):
"""Prepares an attribute for emitting custom change events."""
@@ -33,6 +41,8 @@ class ChangeEvents:
# so detecting it ourselves is easier.
self.device.set_change_event(attr_name, True, False)
self.attributes.append(CaseInsensitiveString(attr_name))
def send_change_event(self, attr_name: str, value: object | None):
"""Emits a CHANGE_EVENT if the attribute has changed value."""
Loading