fix(smaract): stop mangling GCLS/GPL/GST/etc. replies with str.strip()
str.strip(prefix) strips individual characters, not a literal prefix, so
replies made entirely of characters in the prefix (e.g. ":CLS0,0" for
losax) collapsed to '' and crashed float('') in describe(). Other replies
could silently truncate to a wrong value instead. Since the prefix is
already validated by _message_starts_with(), removeprefix() is a safe
drop-in fix for all affected parsers in SmaractController.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -257,7 +257,7 @@ class SmaractController(Controller):
|
||||
def get_communication_mode(self) -> SmaractCommunicationMode:
|
||||
return_val = self.socket_put_and_receive("GCM")
|
||||
if self._message_starts_with(return_val, f":CM"):
|
||||
return SmaractCommunicationMode(int(return_val.strip(":CM")))
|
||||
return SmaractCommunicationMode(int(return_val.removeprefix(":CM")))
|
||||
|
||||
@retry_once
|
||||
@axis_checked
|
||||
@@ -277,7 +277,7 @@ class SmaractController(Controller):
|
||||
"""
|
||||
return_val = self.socket_put_and_receive("GIV")
|
||||
if self._message_starts_with(return_val, f":IV"):
|
||||
return return_val.strip(":IV")
|
||||
return return_val.removeprefix(":IV")
|
||||
|
||||
@retry_once
|
||||
def get_number_of_channels(self) -> int:
|
||||
@@ -294,7 +294,7 @@ class SmaractController(Controller):
|
||||
"""
|
||||
return_val = self.socket_put_and_receive("GNC")
|
||||
if self._message_starts_with(return_val, f":N"):
|
||||
return int(return_val.strip(":N"))
|
||||
return int(return_val.removeprefix(":N"))
|
||||
|
||||
@retry_once
|
||||
def get_system_id(self) -> str:
|
||||
@@ -305,7 +305,7 @@ class SmaractController(Controller):
|
||||
"""
|
||||
return_val = self.socket_put_and_receive("GSI")
|
||||
if self._message_starts_with(return_val, f":ID"):
|
||||
return return_val.strip(":ID")
|
||||
return return_val.removeprefix(":ID")
|
||||
|
||||
@retry_once
|
||||
def reset(self) -> None:
|
||||
@@ -348,7 +348,7 @@ class SmaractController(Controller):
|
||||
if self._message_starts_with(return_val, f":GPL{axis_Id_numeric}"):
|
||||
return [
|
||||
float(limit) / 1e6
|
||||
for limit in return_val.strip(f":GPL{axis_Id_numeric},").split(",")
|
||||
for limit in return_val.removeprefix(f":GPL{axis_Id_numeric},").split(",")
|
||||
]
|
||||
|
||||
@retry_once
|
||||
@@ -376,7 +376,9 @@ class SmaractController(Controller):
|
||||
def get_sensor_type(self, axis_Id_numeric: int) -> SmaractSensorDefinition:
|
||||
return_val = self.socket_put_and_receive(f"GST{axis_Id_numeric}")
|
||||
if self._message_starts_with(return_val, f":ST{axis_Id_numeric}"):
|
||||
return self._sensors.avail_sensors.get(int(return_val.strip(f":ST{axis_Id_numeric},")))
|
||||
return self._sensors.avail_sensors.get(
|
||||
int(return_val.removeprefix(f":ST{axis_Id_numeric},"))
|
||||
)
|
||||
|
||||
@retry_once
|
||||
@axis_checked
|
||||
@@ -419,7 +421,7 @@ class SmaractController(Controller):
|
||||
|
||||
return_val = self.socket_put_and_receive(f"GCLS{axis_Id_numeric}")
|
||||
if self._message_starts_with(return_val, f":CLS{axis_Id_numeric}"):
|
||||
return float(return_val.strip(f":CLS{axis_Id_numeric},")) * 1e6
|
||||
return float(return_val.removeprefix(f":CLS{axis_Id_numeric},")) * 1e6
|
||||
|
||||
def describe(self) -> None:
|
||||
t = PrettyTable()
|
||||
|
||||
Reference in New Issue
Block a user