Skip to content

Commit dc10f8b

Browse files
authored
Merge pull request #28 from python-accelerator-middle-layer/27-range-and-availability-for-multiattribute
Ranges and availability for multiattribute.
2 parents 82375c2 + 81a7cc6 commit dc10f8b

5 files changed

Lines changed: 52 additions & 4 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ classifiers = [
4242

4343
dependencies = [
4444
"PyTango>=10.1.1",
45-
"accelerator-middle-layer<=0.2.2",
45+
"accelerator-middle-layer>=0.2.2",
4646
"pydantic>=2.0"
4747
]
4848

tango/pyaml/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.3.2"
1+
__version__ = "0.3.3"
22

33
import logging.config
44
import os

tango/pyaml/multi_attribute.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from typing import Tuple, Optional
23

34
import numpy as np
45
import pyaml
@@ -28,11 +29,14 @@ class ConfigModel(BaseModel):
2829
Group name.
2930
unit : str, optional
3031
Unit of the attributes.
32+
range : tuple(min, max), optional
33+
Range of valid values. Use null for -∞ or +∞.
3134
"""
3235

3336
attributes: list[str] = []
3437
name: str = ""
3538
unit: str = ""
39+
range: Optional[Tuple[Optional[float], Optional[float]]] = None
3640

3741

3842
class MultiAttribute(DeviceAccessList):
@@ -41,7 +45,9 @@ def __init__(self, cfg: ConfigModel = None):
4145
self._cfg = cfg
4246
if self._cfg:
4347
for attribute in self._cfg.attributes:
44-
attr_config = AttrConfig(attribute=attribute, unit=self._cfg.unit)
48+
attr_config = AttrConfig(
49+
attribute=attribute, unit=self._cfg.unit, range=self._cfg.range
50+
)
4551
attr = Attribute(attr_config)
4652
self.append(attr)
4753

@@ -128,6 +134,20 @@ def readback(self) -> np.array:
128134

129135
return np.array(values)
130136

137+
def get_range(self) -> list[float]:
138+
attr_range: list[float] = []
139+
for device in self:
140+
attr_range.extend(device.get_range())
141+
return attr_range
142+
143+
def check_device_availability(self) -> bool:
144+
available = False
145+
for device in self:
146+
available = device.check_device_availability()
147+
if not available:
148+
break
149+
return available
150+
131151
def unit(self) -> str:
132152
if self._cfg:
133153
return self._cfg.unit

tests/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,21 @@ def config_multi():
7474
return MultiAttrCM(**cfg_dict)
7575

7676

77+
@pytest.fixture
78+
def config_multi_range():
79+
conf = """
80+
attributes:
81+
- "sys/tg_test/1/float_scalar"
82+
- "sys/tg_test/2/float_scalar"
83+
- "sys/tg_test/3/float_scalar"
84+
- "sys/tg_test/4/float_scalar"
85+
unit: "A"
86+
range: [-15, 15]
87+
"""
88+
cfg_dict = yaml.safe_load(conf)
89+
return MultiAttrCM(**cfg_dict)
90+
91+
7792
@pytest.fixture
7893
def config_tango_cs():
7994
conf = """

tests/test_multi_attribute.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import random
22

3-
43
from .mocked_control_system_initialized import MockedControlSystemInitialized
54
from .mocked_device_proxy import MockedDeviceProxy
65
from unittest.mock import patch
@@ -24,3 +23,17 @@ def test_multi_read_write(self, config_multi):
2423
assert len(vals) == len(values)
2524
for index, val in enumerate(vals):
2625
assert val == values[index]
26+
27+
def test_multiattribute_range(self, config_multi_range):
28+
with (
29+
patch("tango.DeviceProxy", new=MockedDeviceProxy),
30+
patch(
31+
"tango.pyaml.controlsystem.TangoControlSystem",
32+
new=MockedControlSystemInitialized,
33+
),
34+
):
35+
ma = MultiAttribute(config_multi_range)
36+
attr_range = ma.get_range()
37+
assert attr_range is not None
38+
assert len(attr_range) == 8 # (4*2)
39+
assert attr_range == [-15, 15, -15, 15, -15, 15, -15, 15]

0 commit comments

Comments
 (0)