ekmmeters.py
def setTime(self, yy, mm, dd, hh, minutes, ss, password="00000000"):
        """ Serial set time with day of week calculation.

        Args:
            yy (int): Last two digits of year.
            mm (int): Month 1-12.
            dd (int): Day 1-31
            hh (int): Hour 0 to 23.
            minutes (int): Minutes 0 to 59.
            ss (int): Seconds 0 to 59.
            password (str): Optional password.

        Returns:
            bool: True on completion and ACK.
        """
        result = False
        self.setContext("setTime")
        try:
            if mm < 1 or mm > 12:
                self.writeCmdMsg("Month must be between 1 and 12")
                self.setContext("")
                return result

            if dd < 1 or dd > 31:
                self.writeCmdMsg("Day must be between 1 and 31")
                self.setContext("")
                return result

            if hh < 0 or hh > 23:
                self.writeCmdMsg("Hour must be between 0 and 23, inclusive")
                self.setContext("")
                return result

            if minutes < 0 or minutes > 59:
                self.writeCmdMsg("Minutes must be between 0 and 59, inclusive")
                self.setContext("")
                return result

            if ss < 0 or ss > 59:
                self.writeCmdMsg("Seconds must be between 0 and 59, inclusive")
                self.setContext("")
                return result

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

            if not self.request(False):
                self.writeCmdMsg("Bad read CRC on setting")
            else:
                if not self.serialCmdPwdAuth(password):
                    self.writeCmdMsg("Password failure")
                else:
                    dt_buf = datetime.datetime(int(yy), int(mm), int(dd), int(hh), int(minutes), int(ss))
                    ekm_log("Writing Date and Time " + dt_buf.strftime("%Y-%m-%d %H:%M"))
                    dayofweek = dt_buf.date().isoweekday()
                    ekm_log("Calculated weekday " + str(dayofweek))

                    req_str = "015731023030363028"
                    req_str += binascii.hexlify(str(yy)[-2:])
                    req_str += binascii.hexlify(str(mm).zfill(2))
                    req_str += binascii.hexlify(str(dd).zfill(2))
                    req_str += binascii.hexlify(str(dayofweek).zfill(2))
                    req_str += binascii.hexlify(str(hh).zfill(2))
                    req_str += binascii.hexlify(str(minutes).zfill(2))
                    req_str += binascii.hexlify(str(ss).zfill(2))
                    req_str += "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(setTime): 06 returned.")
                        result = True
            self.serialPostEnd()
        except:
            ekm_log(traceback.format_exc(sys.exc_info()))

        self.setContext("")
        return result
def setTime(self, yy, mm, dd, hh, minutes, ss, password="00000000"):
        """ Serial set time with day of week calculation.

        Args:
            yy (int): Last two digits of year.
            mm (int): Month 1-12.
            dd (int): Day 1-31
            hh (int): Hour 0 to 23.
            minutes (int): Minutes 0 to 59.
            ss (int): Seconds 0 to 59.
            password (str): Optional password.

        Returns:
            bool: True on completion and ACK.
        """
        result = False
        self.setContext("setTime")
        try:
            if mm < 1 or mm > 12:
                self.writeCmdMsg("Month must be between 1 and 12")
                self.setContext("")
                return result

            if dd < 1 or dd > 31:
                self.writeCmdMsg("Day must be between 1 and 31")
                self.setContext("")
                return result

            if hh < 0 or hh > 23:
                self.writeCmdMsg("Hour must be between 0 and 23, inclusive")
                self.setContext("")
                return result

            if minutes < 0 or minutes > 59:
                self.writeCmdMsg("Minutes must be between 0 and 59, inclusive")
                self.setContext("")
                return result

            if ss < 0 or ss > 59:
                self.writeCmdMsg("Seconds must be between 0 and 59, inclusive")
                self.setContext("")
                return result

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

            if not self.request(False):
                self.writeCmdMsg("Bad read CRC on setting")
            else:
                if not self.serialCmdPwdAuth(password):
                    self.writeCmdMsg("Password failure")
                else:
                    dt_buf = datetime.datetime(int(yy), int(mm), int(dd), int(hh), int(minutes), int(ss))
                    ekm_log("Writing Date and Time " + dt_buf.strftime("%Y-%m-%d %H:%M"))
                    dayofweek = dt_buf.date().isoweekday()
                    ekm_log("Calculated weekday " + str(dayofweek))

                    req_str = "015731023030363028"
                    req_str += binascii.hexlify(str(yy)[-2:])
                    req_str += binascii.hexlify(str(mm).zfill(2))
                    req_str += binascii.hexlify(str(dd).zfill(2))
                    req_str += binascii.hexlify(str(dayofweek).zfill(2))
                    req_str += binascii.hexlify(str(hh).zfill(2))
                    req_str += binascii.hexlify(str(minutes).zfill(2))
                    req_str += binascii.hexlify(str(ss).zfill(2))
                    req_str += "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(setTime): 06 returned.")
                        result = True
            self.serialPostEnd()
        except:
            ekm_log(traceback.format_exc(sys.exc_info()))

        self.setContext("")
        return result
Serial set time with day of week calculation.

        Args:
            yy (int): Last two digits of year.
            mm (int): Month 1-12.
            dd (int): Day 1-31
            hh (int): Hour 0 to 23.
            minutes (int): Minutes 0 to 59.
            ss (int): Seconds 0 to 59.
            password (str): Optional password.

        Returns:
            bool: True on completion and ACK.