Skip to content

Commit

Permalink
why arent plugin protocols working
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Jan 21, 2025
1 parent c7d6c02 commit e4b86c0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pioreactor/cli/calibrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def run_calibration(ctx, device: str, protocol_name: str | None, y: bool) -> Non
assistant = calibration_protocols.get((device, protocol_name))
if assistant is None:
click.echo(
f"No protocols found for calibration device '{device}'. Available {device} protocols: {list(c[1] for c in calibration_protocols.keys() if c[0] == device)}"
f"No protocols found for device '{device}'. Available {device} protocols: {list(c[1] for c in calibration_protocols.keys() if c[0] == device)}"
)
raise click.Abort()

Expand All @@ -113,10 +113,10 @@ def run_calibration(ctx, device: str, protocol_name: str | None, y: bool) -> Non

if not y:
if click.confirm(
f"Do you want to set this calibration as the Active Calibration for {device}?", default=True
f"Do you want to set this calibration as the active calibration for {device}?", default=True
):
calibration_struct.set_as_active_calibration_for_device(device)
click.echo(f"Set{calibration_struct.calibration_name} as the active calibration for {device}.")
click.echo(f"Set {calibration_struct.calibration_name} as the active calibration for {device}.")
else:
click.echo(
f"Okay. You can use 'pio calibration set-active --device {device} --name {calibration_struct.calibration_name}' to set this calibration as the active one."
Expand All @@ -127,6 +127,12 @@ def run_calibration(ctx, device: str, protocol_name: str | None, y: bool) -> Non
)


@calibration.command(name="protocols")
def list_protocols() -> None:
for device, protocol in calibration_protocols.keys():
click.echo(f"{device}: {protocol}")


@calibration.command(name="display")
@click.option("--device", required=True, help="Calibration device.")
@click.option("--name", "calibration_name", required=True, help="Name of calibration to display.")
Expand Down
26 changes: 26 additions & 0 deletions pioreactor/tests/test_calibrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

from pioreactor import exc
from pioreactor.calibrations import CALIBRATION_PATH
from pioreactor.calibrations import calibration_protocols
from pioreactor.calibrations import CalibrationProtocol
from pioreactor.calibrations import load_active_calibration
from pioreactor.calibrations import load_calibration
from pioreactor.calibrations.utils import calculate_poly_curve_of_best_fit
Expand Down Expand Up @@ -225,3 +227,27 @@ def test_mandys_data_for_pathological_poly() -> None:

assert abs(mcal.predict(0.002) - curve_callable(0.002)) < 1e-10
assert abs(mcal.ipredict(0.002) - 0.002) < 0.1


def test_custom_protocol():
class CustomODCalibrationProtocol(CalibrationProtocol):
protocol_name = "custom"
target_device = "od"

@staticmethod
def run(target_device, **kwargs):
pass

assert calibration_protocols[("od", "custom")].__name__ == "CustomODCalibrationProtocol"

class CustomCalibrationProtocolWithList(CalibrationProtocol):
protocol_name = "custom"
target_device = ["A", "B", "C"]

@staticmethod
def run(target_device, **kwargs):
pass

assert calibration_protocols[("A", "custom")].__name__ == "CustomCalibrationProtocolWithList"
assert calibration_protocols[("B", "custom")].__name__ == "CustomCalibrationProtocolWithList"
assert calibration_protocols[("C", "custom")].__name__ == "CustomCalibrationProtocolWithList"

0 comments on commit e4b86c0

Please sign in to comment.