Esempio n. 1
0
    def set_program(self,
                    device: Device,
                    program: VizProgram,
                    transient: bool = False) -> None:
        # don't allow program change on disconnected devices
        if not device.initialized:
            return

        device.program.release()
        program.use()

        device.last_program = device.program
        device.program = program
        if not transient:
            Setting.objects.filter(key=f"last_{device.name}_program").update(
                value=device.last_program.name)
            Setting.objects.filter(key=f"{device.name}_program").update(
                value=device.program.name)
        self.lights.consumers_changed()

        if program.name == "Disabled":
            device.clear()
Esempio n. 2
0
    def set_program(self,
                    device: Device,
                    program: LightProgram,
                    has_lock=False) -> None:
        """Changes the program of the given device to the given program."""
        # don't allow program change on disconnected devices
        if not device.initialized:
            return

        with optional(not has_lock, lights_lock):
            if device.program == program:
                # nothing to do
                return

            device.program.release()
            # see explanation in except ScreenProgramStopped why we don't always use() here
            if not (isinstance(
                    self.programs[storage.get("last_screen_program")],
                    Visualization) and isinstance(
                        self.programs[storage.get("screen_program")],
                        Visualization)):
                program.use()

            device.program = program
            self.consumers_changed()

            if program.name == "Disabled":
                device.clear()

        # Disable the pwr led if the ring is active.
        # The pwr led ruins the clean look of a ring spectrum,
        # and an active led ring is enough of an indicator that the Pi is running.
        if device.name == "ring":
            if program.name == "Disabled":
                leds.enable_pwr_led()
            else:
                leds.disable_pwr_led()
Esempio n. 3
0
 def _handle_brightness_request(self, device: Device,
                                request: WSGIRequest) -> None:
     # raises ValueError on wrong input, caught in option decorator
     value = float(request.POST.get("value"))  # type: ignore
     device.brightness = value
Esempio n. 4
0
 def _handle_monochrome_request(self, device: Device,
                                request: WSGIRequest) -> None:
     # raises ValueError on wrong input, caught in option decorator
     enabled = request.POST.get("value") == "true"  # type: ignore
     device.monochrome = enabled