Skip to content

Implement automatic Enum conversion for device initialization. Add BK 9140 triple output source. Fix type hints to be compatible with python 3.8. #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

TedKus
Copy link
Contributor

@TedKus TedKus commented Oct 17, 2024

This pull request introduces a generic mechanism for automatically converting string values to Enum values during device initialization. This change enhances the flexibility and maintainability of the device initialization process.

Key changes:

  1. Added a new convert_to_enum function that attempts to convert string values to appropriate Enum values based on the Enums defined in the device instance.
  2. Modified the initiaize_device function to use this conversion for all string arguments, regardless of the method being called or the specific Enum involved.

Benefits:

  • Eliminates the need for method-specific conversion logic, making the code more maintainable.
  • Allows JSON configuration files to continue using simple string values while ensuring proper Enum usage in method calls.
  • Automatically handles new devices, methods, and Enums without requiring changes to the initialization logic.
  • Improves code robustness by handling potential conversion errors gracefully.

This change maintains backwards compatibility with existing JSON configurations while providing a more flexible and future-proof solution for device initialization.

Python 3.8:
Some older systems in use are on windows 7 with no upgrade path. They are therefore stuck at python 3.8.
this library doesn't benefit from newer python 3.9+ syntax in any meaningful way, therefore reverted some type hints for backwards compatibility. The discovery of the Enum issue resulted from this attempt.

Add Source: Original intent was to add BK 9140 triple output source. This source inherits from but differs from the Keithley in that channel numbers start from zero and several strings for setting the output have different syntax. Added a couple of custom commands for slew rate since it can.
Also added a remote function to the chroma 62000. Note that RWLock is being used in Keithley for remote control, this differs from just remote in that the panel is locked out until released to local. Safe to prevent device tamper, but can be an irritation in development where scripts pause.

Add Manifest.in to make sure that the build of the package always finds all of the subfolder modules when using pip install .

it differs from the keithley in a few commands
fix(pyproject): python 3.8 support
fix(tox): python 3.8 support
fix(type): revert typehint to python 3.8 style
This method returns the value of the Enum member as a string.
changed `mode.value` to `str(mode)`.
This calls the `__str__` method,
returns the string value of the Enum member
add convert_to_enum
Attempt to convert a string value to an Enum value if a matching Enum exists in the instance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant