Skip to content

Commit

Permalink
fix id lookup issue
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Jun 13, 2024
1 parent dfc9a87 commit 14d2ef5
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 71 deletions.
8 changes: 4 additions & 4 deletions src/ibek/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class EntityDefinition(BaseSettings):
)

def _get_id_arg(self):
"""Returns the name of the ID argument for this definition, if it exists"""
for arg in self.params:
if isinstance(arg, IdParam):
return arg.name
"""Returns the value of the ID argument for this definition, if it exists"""
for name, value in self.params.items():
if isinstance(value, IdParam):
return name
12 changes: 5 additions & 7 deletions src/ibek/ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,21 @@ def add_ibek_attributes(self):
value = value.replace("True", "true")
value = value.replace("False", "false")
value = json.loads(value)
# likewise for bools
except:
print(
f"ERROR: fail to decode {value} as a {model_field.annotation}"
)
raise
setattr(self, arg, value)
# update the entity_dict with the rendered value
entity_dict[arg] = value

if model_field.annotation == object:
# look up the actual object by it's id
if isinstance(value, str):
value = get_entity_by_id(value)
setattr(self, arg, value)
# update the entity_dict with looked up object
entity_dict[arg] = value

# update this entity instance with the rendered value
setattr(self, arg, value)
# update the entity_dict with the rendered value
entity_dict[arg] = value

if arg in ids:
# add this entity to the global id index
Expand Down
112 changes: 56 additions & 56 deletions tests/samples/support/gauges.ibek.support.yaml
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
# yaml-language-server: $schema=https://github.com/epics-containers/ibek/releases/download/1.5.3/ibek.support.schema.json
# yaml-language-server: $schema=../schemas/ibek.support.schema.json

module: gauges

# Pretend support for vacuum space to test initialisation of a gauge group

defs:
- name: Mks937bGauge
description: |-
MKS 937b Gauge controller
params:
port:
type: object
description: |-
Asyn port that connects to the device
name:
type: id
description: |-
name for the Device
P:
type: str
description: |-
PV prefix
- name: Mks937bGauge
description: |-
MKS 937b Gauge controller
params:
port:
type: object
description: |-
Asyn port that connects to the device
name:
type: id
description: |-
name for the Device
P:
type: str
description: |-
PV prefix
- name: GaugeGroup
description: |-
Group of gauges
params:
name:
type: id
description: |-
name for the
gauge1:
type: object
description: |-
First gauge
gauge2:
type: object
description: |-
Second gauge
# default to the id of the gauge object we want as default
default: |-
{{gauge1.name}}
gauge3:
type: object
description: |-
Third gauge
default: |
{{gauge1.name}}
gauge4:
type: object
description: |-
Fourth gauge
default: |
{{gauge1.name}}
- name: GaugeGroup
description: |-
Group of gauges
params:
name:
type: id
description: |-
name for the
gauge1:
type: object
description: |-
First gauge
gauge2:
type: object
description: |-
Second gauge
# default to the first gauge object
default: |-
{{gauge1}}
gauge3:
type: object
description: |-
Third gauge
default: |
{{gauge1}}
gauge4:
type: object
description: |-
Fourth gauge
default: |
{{gauge1}}
pre_init:
- value: |2
pre_init:
- value: |
# GAUGE GROUP GAUGE DEFAULTS TEST
# gauge1 P is {{gauge1.P}}
# gauge2 P is {{gauge2.P}}
# gauge3 P is {{gauge3.P}}
# gauge4 P is {{gauge4.P}}
# gauge4 baud is {{gauge4.port.baud}}
# GAUGE GROUP GAUGE DEFAULTS TEST
# gauge1 P is {{gauge1.P}}
# gauge2 P is {{gauge2.P}}
# gauge3 P is {{gauge3.P}}
# gauge4 P is {{gauge4.P}}
# gauge4 baud is {{gauge4.port.baud}}
10 changes: 6 additions & 4 deletions tests/samples/support/quadem.ibek.support.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ defs:
pre_init:
- value: |
################################################################################
# Just demonstrating that Entities can have their own pre_init AND SubEntities.
# This is the pre_init for quadem.Plugins device with id {{PORTPREFIX}}
################################################################################
################################################################################
# Just demonstrating that Entities can have their own pre_init AND SubEntities.
# This is the pre_init for quadem.Plugins device with id {{PORTPREFIX}}
################################################################################
#
shared:
- &stats { type: ADCore.NDStats, P: "{{DEVICE.P}}", NCHANS: "{{STAT_NCHAN}}", XSIZE: "{{STAT_XSIZE}}", YSIZE: 0, HIST_SIZE: "{{HIST_SIZE}}", NDARRAY_PORT: "{{DEVICE}}", ENABLED: 1 }
Expand Down

0 comments on commit 14d2ef5

Please sign in to comment.