You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromtypingimportFinal, Type, OptionalclassDeviceManager:
DEFAULT_CONNECTION_TIMEOUT: Final[float] =5.0def__init__(self):
self.active_devices: dict[str, AnyDevice] = {}
self.beamline_name: str=""self.path_provider: Optional[UpdatingPathProvider] =Nonedefset_beamline(self, beamline: str):
"""Set the beamline name."""self.beamline_name=beamlinedefclear_devices(self):
"""Clear all active devices."""self.active_devices.clear()
defclear_device(self, name: str):
"""Clear a specific device by name."""self.active_devices.pop(name, None)
deflist_active_devices(self) ->list[str]:
"""List the names of all active devices."""returnlist(self.active_devices.keys())
defactive_device_is_same_type(
self, active_device: AnyDevice, device: Type[AnyDevice]
) ->bool:
"""Check if the active device is of the same type as the provided device."""returnisinstance(active_device, device)
# Usage Examplemanager=DeviceManager()
manager.set_beamline("BL1")
manager.clear_devices()
# Add a device (Example)manager.active_devices['device1'] =AnyDevice()
# Check if a device is the same typeis_same_type=manager.active_device_is_same_type(manager.active_devices['device1'], AnyDevice)
It's a maintainability issue, as the state of the whole application, such as blueapi using this library can be subject to hard to predict changes.
OOP takes care to only allow state mutation through setters, at the moment this is quite haphazard.
This change would definitely be a breaking one to the downstream projects, however not too difficult to implement here.
The text was updated successfully, but these errors were encountered: