diff --git a/pyproject.toml b/pyproject.toml index 7dcf719..c8ba179 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,7 +62,6 @@ ignore = [ "ISC001", # Conflicts with other rules "PLR2004", # Just annoying, not really useful "PLR0912", - "PLW2901", ] select = ["ALL"] diff --git a/roombapy/roomba.py b/roombapy/roomba.py index 692e21b..ef4c3b6 100755 --- a/roombapy/roomba.py +++ b/roombapy/roomba.py @@ -311,12 +311,14 @@ def decode_topics(self, state, prefix=None): to strings to avoid unicode representations """ for key, value in state.items(): + mutable_key = key if isinstance(value, dict): if prefix is None: self.decode_topics(value, key) else: self.decode_topics(value, prefix + "_" + key) else: + mutable_value = value if isinstance(value, list): newlist = [] for i in value: @@ -324,37 +326,42 @@ def decode_topics(self, state, prefix=None): for ki, vi in i.items(): newlist.append((str(ki), vi)) else: + val = i if isinstance(i, str): - i = str(i) - newlist.append(i) - value = newlist + val = str(i) + newlist.append(val) + mutable_value = newlist if prefix is not None: - key = prefix + "_" + key + mutable_key = prefix + "_" + key # all data starts with this, so it's redundant - key = key.replace("state_reported_", "") + mutable_key = mutable_key.replace("state_reported_", "") # save variables for drawing map - if key == "pose_theta": - self.co_ords["theta"] = value - if key == "pose_point_x": # x and y are reversed... - self.co_ords["y"] = value - if key == "pose_point_y": - self.co_ords["x"] = value - if key == "bin_full": - self.bin_full = value - if key == "cleanMissionStatus_error": + if mutable_key == "pose_theta": + self.co_ords["theta"] = mutable_value + if mutable_key == "pose_point_x": # x and y are reversed... + self.co_ords["y"] = mutable_value + if mutable_key == "pose_point_y": + self.co_ords["x"] = mutable_value + if mutable_key == "bin_full": + self.bin_full = mutable_value + if mutable_key == "cleanMissionStatus_error": try: - self.error_code = value - self.error_message = ROOMBA_ERROR_MESSAGES[value] + self.error_code = mutable_value + self.error_message = ROOMBA_ERROR_MESSAGES[ + mutable_value + ] except KeyError as e: self.log.warning( "Error looking up Roomba error message: %s", e ) - self.error_message = "Unknown Error number: %s" % value + self.error_message = ( + "Unknown Error number: %s" % mutable_value + ) if key == "cleanMissionStatus_phase": self.previous_cleanMissionStatus_phase = ( self.cleanMissionStatus_phase ) - self.cleanMissionStatus_phase = value + self.cleanMissionStatus_phase = mutable_value if prefix is None: self.update_state_machine()