diff --git a/python/lsst/ts/tunablelaser/canbus_modules.py b/python/lsst/ts/tunablelaser/canbus_modules.py index d570312..1a1b477 100755 --- a/python/lsst/ts/tunablelaser/canbus_modules.py +++ b/python/lsst/ts/tunablelaser/canbus_modules.py @@ -45,6 +45,7 @@ "MidiOPG", "E5DCB", ] + import logging from . import interfaces diff --git a/python/lsst/ts/tunablelaser/component.py b/python/lsst/ts/tunablelaser/component.py index 17b955a..3334961 100755 --- a/python/lsst/ts/tunablelaser/component.py +++ b/python/lsst/ts/tunablelaser/component.py @@ -142,7 +142,7 @@ async def set_optical_configuration(self, optical_configuration): Parameters ---------- - optical_configuration: `str`, {straight-through,F1,F2} + optical_configuration: `str`, OpticalConfiguration(enum.StrEnum) The optical alignment to switch to. """ self.maxi_opg.optical_alignment = optical_configuration diff --git a/python/lsst/ts/tunablelaser/config_schema.py b/python/lsst/ts/tunablelaser/config_schema.py index e6b4f10..2f1396d 100644 --- a/python/lsst/ts/tunablelaser/config_schema.py +++ b/python/lsst/ts/tunablelaser/config_schema.py @@ -23,8 +23,10 @@ import yaml +from .enums import OpticalConfiguration + CONFIG_SCHEMA = yaml.safe_load( - """ + f""" $schema: http://json-schema.org/draft-07/schema# $id: https://github.com/lsst-ts/ts_TunableLaser/blob/master/schema/TunableLaser.yaml title: TunableLaser v4 @@ -46,7 +48,7 @@ type: number optical_configuration: description: The mirror alignment configuration for the laser - enum: ["SCU","No SCU","F1 SCU","F1 No SCU","F2 SCU","F2 No SCU"] + enum: {[e.value for e in OpticalConfiguration]} wavelength: description: The min and max wavelengths for the laser type: object diff --git a/python/lsst/ts/tunablelaser/csc.py b/python/lsst/ts/tunablelaser/csc.py index e751a51..ff7e017 100755 --- a/python/lsst/ts/tunablelaser/csc.py +++ b/python/lsst/ts/tunablelaser/csc.py @@ -27,10 +27,11 @@ import asyncio from lsst.ts import salobj, utils -from lsst.ts.xml.enums import TunableLaser +from lsst.ts.xml.enums.TunableLaser import LaserDetailedState, LaserErrorCode from . import __version__, component, mock_server from .config_schema import CONFIG_SCHEMA +from .enums import OpticalConfiguration def run_tunablelaser(): @@ -119,7 +120,7 @@ async def telemetry(self): or self.model.m_cpu800.power_register_2.register_value == "FAULT" ): await self.fault( - code=TunableLaser.LaserErrorCode.HW_CPU_ERROR, + code=LaserErrorCode.HW_CPU_ERROR, report=( f"cpu8000 fault:{self.model.cpu8000.fault_register.register_value}" f"m_cpu800 fault:{self.model.m_cpu800.fault_register.register_value}" @@ -166,7 +167,7 @@ def assert_substate(self, substates, action): """ if self.evt_detailedState.data.detailedState not in [ - TunableLaser.LaserDetailedState(substate) for substate in substates + LaserDetailedState(substate) for substate in substates ]: raise salobj.ExpectedError( f"{action} not allowed in state {self.evt_detailedState.data.detailedState!r}" @@ -195,7 +196,7 @@ async def handle_summary_state(self): if not self.connected and self.model is not None: await self.evt_detailedState.set_write( - detailedState=TunableLaser.LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE + detailedState=LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE ) try: await self.model.connect() @@ -212,7 +213,7 @@ async def handle_summary_state(self): ): await self.model.stop_propagating() await self.publish_new_detailed_state( - TunableLaser.LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE + LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE ) if self.telemetry_task.done(): self.telemetry_task = asyncio.create_task(self.telemetry()) @@ -245,18 +246,18 @@ async def do_setBurstMode(self, data): await self.model.set_burst_mode(data.count) await self.evt_burstModeSet.set_write() if self.evt_detailedState.data.detailedState in [ - TunableLaser.LaserDetailedState.PROPAGATING_BURST_MODE, - TunableLaser.LaserDetailedState.PROPAGATING_CONTINUOUS_MODE, + LaserDetailedState.PROPAGATING_BURST_MODE, + LaserDetailedState.PROPAGATING_CONTINUOUS_MODE, ]: await self.publish_new_detailed_state( - TunableLaser.LaserDetailedState.PROPAGATING_BURST_MODE + LaserDetailedState.PROPAGATING_BURST_MODE ) if self.evt_detailedState.data.detailedState in [ - TunableLaser.LaserDetailedState.NONPROPAGATING_BURST_MODE, - TunableLaser.LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE, + LaserDetailedState.NONPROPAGATING_BURST_MODE, + LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE, ]: await self.publish_new_detailed_state( - TunableLaser.LaserDetailedState.NONPROPAGATING_BURST_MODE + LaserDetailedState.NONPROPAGATING_BURST_MODE ) else: raise salobj.ExpectedError("Not connected.") @@ -303,8 +304,8 @@ async def do_startPropagateLaser(self, data): self.assert_enabled() self.assert_substate( [ - TunableLaser.LaserDetailedState.NONPROPAGATING_BURST_MODE, - TunableLaser.LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE, + LaserDetailedState.NONPROPAGATING_BURST_MODE, + LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE, ], "startPropagateLaser", ) @@ -324,8 +325,8 @@ async def do_stopPropagateLaser(self, data): self.assert_enabled() self.assert_substate( [ - TunableLaser.LaserDetailedState.PROPAGATING_BURST_MODE, - TunableLaser.LaserDetailedState.PROPAGATING_CONTINUOUS_MODE, + LaserDetailedState.PROPAGATING_BURST_MODE, + LaserDetailedState.PROPAGATING_CONTINUOUS_MODE, ], "stopPropagateLaser", ) @@ -333,17 +334,17 @@ async def do_stopPropagateLaser(self, data): await self.model.stop_propagating() if ( self.evt_detailedState.data.detailedState - == TunableLaser.LaserDetailedState.PROPAGATING_BURST_MODE + == LaserDetailedState.PROPAGATING_BURST_MODE ): await self.publish_new_detailed_state( - TunableLaser.LaserDetailedState.NONPROPAGATING_BURST_MODE + LaserDetailedState.NONPROPAGATING_BURST_MODE ) elif ( self.evt_detailedState.data.detailedState - == TunableLaser.LaserDetailedState.PROPAGATING_CONTINUOUS_MODE + == LaserDetailedState.PROPAGATING_CONTINUOUS_MODE ): await self.publish_new_detailed_state( - TunableLaser.LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE + LaserDetailedState.NONPROPAGATING_CONTINUOUS_MODE ) else: raise salobj.ExpectedError("Not connected.") @@ -366,7 +367,7 @@ async def do_triggerBurst(self, data): """Trigger a burst.""" self.assert_enabled() self.assert_substate( - [TunableLaser.LaserDetailedState.PROPAGATING_BURST_MODE], + [LaserDetailedState.PROPAGATING_BURST_MODE], "Trigger", ) await self.model.trigger_burst() @@ -403,11 +404,18 @@ async def do_setOpticalConfiguration(self, data): alignment of the laser. """ self.assert_enabled() + try: + configuration = OpticalConfiguration(data.configuration) + except Exception: + raise salobj.ExpectedError( + f"Optical Configuration {data.configuration} not included in allowable options" + ) + if self.connected: if self.laser_type == "Main": # only main laser can do this - await self.model.set_optical_configuration(data.configuration) + await self.model.set_optical_configuration(configuration) await self.evt_opticalConfiguration.set_write( - configuration=data.configuration + configuration=configuration ) else: raise salobj.ExpectedError("Not connected") @@ -420,7 +428,7 @@ async def publish_new_detailed_state(self, new_sub_state): new_sub_state : `LaserDetailedState` The new sub state to publish. """ - new_sub_state = TunableLaser.LaserDetailedState(new_sub_state) + new_sub_state = LaserDetailedState(new_sub_state) await self.evt_detailedState.set_write(detailedState=new_sub_state) async def configure(self, config): diff --git a/python/lsst/ts/tunablelaser/enums.py b/python/lsst/ts/tunablelaser/enums.py index 729e607..3a03660 100644 --- a/python/lsst/ts/tunablelaser/enums.py +++ b/python/lsst/ts/tunablelaser/enums.py @@ -1,6 +1,7 @@ __all__ = ["Power", "Mode", "Output", "OpticalConfiguration"] import enum +import warnings class Power(enum.StrEnum): @@ -33,18 +34,26 @@ class Output(enum.StrEnum): """Maximum energy level for the laser.""" -class OpticalConfiguration(enum.StrEnum): - """Configuration of the optical output""" - - SCU = "SCU" - """Pass the beam straight-through the SCU.""" - F1_SCU = "F1 SCU" - """Direct the beam through the F1 after passing through the SCU.""" - F2_SCU = "F2 SCU" - """Direct the beam through the F2 after passing through the SCU.""" - NO_SCU = "No SCU" - """Pass the beam straight-through.""" - F1_NO_SCU = "F1 No SCU" - """Pass the beam to F1 output.""" - F2_NO_SCU = "F2 No SCU" - """Pass the beam to F2 output.""" +# TODO: (DM-46168) Revert workaround for TunableLaser XML changes +try: + from lsst.ts.xml.enums.TunableLaser import OpticalConfiguration +except ImportError: + warnings.warn( + "OpticalConfiguration enumeration not availble in ts-xml. Using local version." + ) + + class OpticalConfiguration(enum.StrEnum): + """Configuration of the optical output""" + + SCU = "SCU" + """Pass the beam straight-through the SCU.""" + F1_SCU = "F1 SCU" + """Direct the beam through the F1 after passing through the SCU.""" + F2_SCU = "F2 SCU" + """Direct the beam through the F2 after passing through the SCU.""" + NO_SCU = "No SCU" + """Pass the beam straight-through.""" + F1_NO_SCU = "F1 No SCU" + """Pass the beam to F1 output.""" + F2_NO_SCU = "F2 No SCU" + """Pass the beam to F2 output."""