Update on Venus Response Codes

We recently updated how response strings are parsed in PyHamilton to be a lot more clear.

In PyHamilton, response strings are messages sent from Venus to Python after a command is executed in the universal method (…noFan.hsl). Python reads that response string and decides if the command passes or fails. This code was recently rationalized to clearly enforce a set of rules on whether or not a response passed.

This code ensures that response strings containing only a 1 as a string or integer would pass, and that response strings containing a leading 0 and other characters will also pass. Every other response fails or is considered unknown.

    def _compute_status(self):
        is_unknown = 'step-return1' not in self.raw
        if is_unknown:
            return HamiltonResponseStatus.UNKNOWN

        response = json.loads(self.raw)['step-return1']

        is_success = response == 1 or           \
            (
                isinstance(response, str) and   \
                len(response) == 1 and          \
                response[0] == '1'
            ) or                                \
            (
                isinstance(response, str) and   \
                len(response) > 1 and           \
                response[0] == '0'
            )
        is_failed = response == 0 or            \
            (
                isinstance(response, str) and   \
                len(response) == 1 and          \
                response[0] != '1'
            ) or                                \
            (
                isinstance(response, str) and   \
                len(response.strip()) > 1 and   \
                response.strip()[0] != '0'
            )

        if is_failed:
            return HamiltonResponseStatus.FAILED

        if is_success:
            return HamiltonResponseStatus.SUCCESS

        return HamiltonResponseStatus.UNKNOWN

All equipment integrations have to reflect this in their response code, and in some cases the method has to assign certain variables manually and override the original error code to maintain conformity.