frappy_demo.test: add parameter for testing error messages

Change-Id: Ifbf9d6829be373417d3bf1ff398d2aee283d8c9a
This commit is contained in:
zolliker 2025-01-17 15:01:11 +01:00
parent eee63ee3df
commit b7bc81710d

View File

@ -26,7 +26,7 @@ from frappy.datatypes import FloatRange, StringType, ValueType, TupleOf, StructO
from frappy.modules import Communicator, Drivable, Parameter, Property, Readable, Module, Attached from frappy.modules import Communicator, Drivable, Parameter, Property, Readable, Module, Attached
from frappy.params import Command from frappy.params import Command
from frappy.dynamic import Pinata from frappy.dynamic import Pinata
from frappy.errors import RangeError from frappy.errors import RangeError, HardwareError
class Pin(Pinata): class Pin(Pinata):
def scanModules(self): def scanModules(self):
@ -72,8 +72,12 @@ class Heater(Drivable):
maxheaterpower = Parameter('maximum allowed heater power', maxheaterpower = Parameter('maximum allowed heater power',
datatype=FloatRange(0, 100), unit='W', datatype=FloatRange(0, 100), unit='W',
) )
error_message = Parameter('simulated error message', StringType(),
default='', readonly=False)
def read_value(self): def read_value(self):
if self.error_message:
raise HardwareError(self.error_message)
return round(100 * random.random(), 1) return round(100 * random.random(), 1)
def write_target(self, target): def write_target(self, target):