ekmmeters.py
def setRelay(self, seconds, relay, status, password="00000000"):
        """Serial call to set relay.

        Args:
            seconds (int): Seconds to hold, ero is hold forever. See :class:`~ekmmeters.RelayInterval`.
            relay (int): Selected relay, see :class:`~ekmmeters.Relay`.
            status (int): Status to set, see :class:`~ekmmeters.RelayState`
            password (str): Optional password

        Returns:
            bool: True on completion and ACK.
        """
        result = False
        self.setContext("setRelay")
        try:
            self.clearCmdMsg()

            if len(password) != 8:
                self.writeCmdMsg("Invalid password length.")
                self.setContext("")
                return result

            if seconds < 0 or seconds > 9999:
                self.writeCmdMsg("Relay duration must be between 0 and 9999.")
                self.setContext("")
                return result

            if not self.requestA():
                self.writeCmdMsg("Bad read CRC on setting")
            else:
                if not self.serialCmdPwdAuth(password):
                    self.writeCmdMsg("Password failure")
                else:
                    req_str = ""
                    req_str = ("01573102303038" +
                               binascii.hexlify(str(relay)).zfill(2) +
                               "28" +
                               binascii.hexlify(str(status)).zfill(2) +
                               binascii.hexlify(str(seconds).zfill(4)) + "2903")
                    req_str += self.calc_crc16(req_str[2:].decode("hex"))
                    self.m_serial_port.write(req_str.decode("hex"))
                    if self.m_serial_port.getResponse(self.getContext()).encode("hex") == "06":
                        self.writeCmdMsg("Success: 06 returned.")
                        result = True
            self.serialPostEnd()
        except:
            ekm_log(traceback.format_exc(sys.exc_info()))

        self.setContext("")
        return result
def setRelay(self, seconds, relay, status, password="00000000"):
        """Serial call to set relay.

        Args:
            seconds (int): Seconds to hold, ero is hold forever. See :class:`~ekmmeters.RelayInterval`.
            relay (int): Selected relay, see :class:`~ekmmeters.Relay`.
            status (int): Status to set, see :class:`~ekmmeters.RelayState`
            password (str): Optional password

        Returns:
            bool: True on completion and ACK.
        """
        result = False
        self.setContext("setRelay")
        try:
            self.clearCmdMsg()

            if len(password) != 8:
                self.writeCmdMsg("Invalid password length.")
                self.setContext("")
                return result

            if seconds < 0 or seconds > 9999:
                self.writeCmdMsg("Relay duration must be between 0 and 9999.")
                self.setContext("")
                return result

            if not self.requestA():
                self.writeCmdMsg("Bad read CRC on setting")
            else:
                if not self.serialCmdPwdAuth(password):
                    self.writeCmdMsg("Password failure")
                else:
                    req_str = ""
                    req_str = ("01573102303038" +
                               binascii.hexlify(str(relay)).zfill(2) +
                               "28" +
                               binascii.hexlify(str(status)).zfill(2) +
                               binascii.hexlify(str(seconds).zfill(4)) + "2903")
                    req_str += self.calc_crc16(req_str[2:].decode("hex"))
                    self.m_serial_port.write(req_str.decode("hex"))
                    if self.m_serial_port.getResponse(self.getContext()).encode("hex") == "06":
                        self.writeCmdMsg("Success: 06 returned.")
                        result = True
            self.serialPostEnd()
        except:
            ekm_log(traceback.format_exc(sys.exc_info()))

        self.setContext("")
        return result
Serial call to set relay.

        Args:
            seconds (int): Seconds to hold, ero is hold forever. See :class:`~ekmmeters.RelayInterval`.
            relay (int): Selected relay, see :class:`~ekmmeters.Relay`.
            status (int): Status to set, see :class:`~ekmmeters.RelayState`
            password (str): Optional password

        Returns:
            bool: True on completion and ACK.