Better cast to string for Params
This commit is contained in:
parent
9e88f68fe0
commit
ccd63de9ea
@ -135,6 +135,9 @@ class Nucon(Enum):
|
||||
self.param_type = param_type
|
||||
self.is_writable = is_writable
|
||||
|
||||
def __str__(self):
|
||||
return self.id
|
||||
|
||||
@property
|
||||
def enum_type(self) -> Type[Enum]:
|
||||
return self.param_type if issubclass(self.param_type, Enum) else None
|
||||
@ -170,7 +173,10 @@ class Nucon(Enum):
|
||||
return [param for param in cls if param.is_writable]
|
||||
|
||||
@classmethod
|
||||
def get(cls, parameter: 'Nucon') -> Union[float, int, bool, str, Enum]:
|
||||
def get(cls, parameter: Union['Nucon', str]) -> Union[float, int, bool, str, Enum]:
|
||||
if isinstance(parameter, str):
|
||||
parameter = cls[parameter]
|
||||
|
||||
if NuconConfig.dummy_mode:
|
||||
return cls._get_dummy_value(parameter)
|
||||
|
||||
@ -212,7 +218,10 @@ class Nucon(Enum):
|
||||
return cls.get_multiple(list(cls))
|
||||
|
||||
@classmethod
|
||||
def set(cls, parameter: 'Nucon', value: Union[float, int, bool, str, Enum], force: bool = False) -> None:
|
||||
def set(cls, parameter: Union['Nucon', str], value: Union[float, int, bool, str, Enum], force: bool = False) -> None:
|
||||
if isinstance(parameter, str):
|
||||
parameter = cls[parameter]
|
||||
|
||||
if not force and not parameter.is_writable:
|
||||
raise ValueError(f"Parameter {parameter.name} is not writable")
|
||||
|
||||
@ -226,7 +235,8 @@ class Nucon(Enum):
|
||||
response = requests.post(NuconConfig.base_url, params={"variable": parameter.name, "value": str(value), "force": str(force).lower()})
|
||||
|
||||
if response.status_code != 200:
|
||||
raise E
|
||||
raise Exception(f"Failed to set parameter {parameter.name}. Status code: {response.status_code}")
|
||||
|
||||
|
||||
# Example usage
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
Reference in New Issue
Block a user