# Copyright (C) 2026 RemoteRF # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # Minimal example schema for documentation. # Replace DummyCounterDevice with the real vendor library or wrapper for your # hardware, then adapt the exposed methods to match what you want clients to # call remotely. from remoteRF_server.common.idl import DeviceSchema, idl_expose, idl_register class DummyCounterDevice: def __init__(self, start=0, step=1, label="Dummy Counter"): self.count = int(start) self.step = int(step) self.label = str(label) self.enabled = True def increment(self, amount=None, repeat=1): step = self.step if amount is None else int(amount) self.count += step * int(repeat) return self.count def reset(self): self.count = 0 @idl_register("dummy_counter") class DummyCounterSchema(DeviceSchema): device_type = "dummy_counter" client_class = "DummyCounter" driver_version = "0.1.0" @staticmethod def make_device(**kwargs): return DummyCounterDevice( start=kwargs.get("start", 0), step=kwargs.get("step", 1), label=kwargs.get("label", "Dummy Counter"), ) @idl_expose(kind="get", doc="Human-readable device label.") def get_label(self): return self.device.label @idl_expose(kind="get") def get_count(self): return int(self.device.count) @idl_expose(kind="get") def get_enabled(self): return bool(self.device.enabled) @idl_expose(kind="set") def set_enabled(self, value): self.device.enabled = bool(value) @idl_expose(kind="call") def call_increment( self, amount: int = None, *, repeat: int = 1, ): """Increment by amount, optionally more than once.""" return self.device.increment(amount=amount, repeat=repeat) @idl_expose def call_reset(self): """Reset the dummy counter.""" self.device.reset() return 0 @idl_expose(kind="call") def call_identify(self): return f"{self.device.label} count={self.device.count}"