示例#1
0
    def timeDaemon(self):
        pre = previous.list_profile()
        if 'previous' in pre:
            pre = 'previous'
        else:
            return
        if self.onTimeTxt != "00:00" and self.offTimeTxt != "00:00":
            onTime = datetime.datetime.strptime(self.onTimeTxt, '%H:%M').time()
            offTime = datetime.datetime.strptime(self.offTimeTxt,
                                                 '%H:%M').time()

            if time_in_range(offTime, onTime, datetime.datetime.now().time()):
                if not self.doneOff:
                    self.checkAudio()
                    try:
                        with serial.Serial(self.portTxt.text(), 256000) as ser:
                            print("Turning off")
                            hue.power(ser, 0, 'off')
                            hue.unitled(ser, 'off')
                            self.doneOff = True
                            self.doneOn = False
                    except serial.serialutil.SerialException:
                        self.error(
                            "Serial port is invalid. Try /dev/ttyACM0 for Linux or COM3 or COM4 for Windows"
                        )
            else:
                if not self.doneOn:
                    self.checkAudio()
                    try:
                        with serial.Serial(self.portTxt.text(), 256000) as ser:
                            print("Turning on")
                            hue.profile_apply(ser, pre)
                            hue.unitled(ser, 'on')
                            self.doneOn = True
                            self.doneOff = False
                    except serial.serialutil.SerialException:
                        self.error(
                            "Serial port is invalid. Try /dev/ttyACM0 for Linux or COM3 or COM4 for Windows"
                        )
示例#2
0
    def profileApply(self):
        self.checkAudio()
        try:
            with serial.Serial(self.portTxt.text(), 256000) as ser:
                if self.getChannel() == None:
                    hue.power(ser, 0, "off")
                else:
                    out = hue.profile_apply(
                        ser,
                        self.profileList.currentItem().text())
        except serial.serialutil.SerialException:
            self.error(
                "Serial port is invalid. Try /dev/ttyACM0 for Linux or COM3 or COM4 for Windows"
            )

        if out:
            self.animatedColors = out['colors']
            self.animatedSpeed.setValue(out['speed'])
            self.animatedApply()