Skip to content

Require a context for emulator constructors - #122

Merged
arnobaer merged 2 commits into
mainfrom
refactor/emulator-context
Jul 30, 2026
Merged

Require a context for emulator constructors#122
arnobaer merged 2 commits into
mainfrom
refactor/emulator-context

Conversation

@arnobaer

Copy link
Copy Markdown
Member

Require Context as a mandatory constructor argument for all emulator classes.

Update the factory and runtime creation paths to always construct emulators with a Context, and adapt the test suite to the new constructor contract. This unifies emulator initialization and makes context-dependent state available during object construction, e.g.

import random

from comet.emulator import Context, Emulator, message

class MyEmulator(Emulator):
    def __init__(self, context: Context) -> None:
        super().__init__(context)

        options = context.options

        self.humidity_min = options.get("humidity_min", 42.0)  # this was not possible in ctor!
        self.humidity_max = options.get("humidity_max", 43.0)

    @message("HUM\?$")
    def get_humidity(self) -> float:
        return random.uniform(self.humidity_min, self.humidity_max)

This change will permit introducing a service bus in future releases so e.g. scripts then can interact with emulators. via a common TCP socket.

@arnobaer arnobaer added this to the 1.6.x milestone Jul 30, 2026
@arnobaer arnobaer self-assigned this Jul 30, 2026
@arnobaer arnobaer added the enhancement New feature or request label Jul 30, 2026
@arnobaer
arnobaer merged commit a570b7b into main Jul 30, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant