コード例 #1
0
def test_on_register_callback(thing):
    # Build extension
    def f(extension):
        extension.callback_called = True

    extension = BaseExtension("org.labthings.tests.extension")
    extension.callback_called = False
    extension.on_register(f, args=(extension, ))
    # Add extension
    thing.register_extension(extension)

    # Check callback
    assert extension.callback_called
コード例 #2
0
    logging.info("Extension registered")


def ext_on_my_component(component):
    logging.info(f"{component} registered and noticed by extension")


static_folder = path_relative_to(__file__, "static")

example_extension = BaseExtension(
    "org.labthings.examples.extension", static_folder=static_folder
)

example_extension.add_view(ExtensionMeasurementAction, "/measure", endpoint="measure")

example_extension.on_register(ext_on_register)
example_extension.on_component("org.labthings.example.mycomponent", ext_on_my_component)


"""
Class for our lab component functionality. This could include serial communication,
equipment API calls, network requests, or a "virtual" device as seen here.
"""


class MyComponent:
    def __init__(self):
        self.x_range = range(-100, 100)
        self.magic_denoise = 200

    def noisy_pdf(self, x, mu=0.0, sigma=25.0):