コード例 #1
0
def test_get_color_wheel(colors, error_expected):

    # SUT
    if error_expected:
        with pytest.raises(error_expected):
            colors = get_color_wheel(colors)
    else:
        colors = get_color_wheel(colors)
コード例 #2
0
    async def init(self) -> None:
        manual_steps = self.args.get("manual_steps", DEFAULT_MANUAL_STEPS)
        automatic_steps = self.args.get("automatic_steps",
                                        DEFAULT_AUTOMATIC_STEPS)
        self.min_brightness = self.args.get("min_brightness",
                                            DEFAULT_MIN_BRIGHTNESS)
        self.max_brightness = self.args.get("max_brightness",
                                            DEFAULT_MAX_BRIGHTNESS)
        self.min_white_value = self.args.get("min_white_value",
                                             DEFAULT_MIN_WHITE_VALUE)
        self.max_white_value = self.args.get("max_white_value",
                                             DEFAULT_MAX_WHITE_VALUE)
        self.min_color_temp = self.args.get("min_color_temp",
                                            DEFAULT_MIN_COLOR_TEMP)
        self.max_color_temp = self.args.get("max_color_temp",
                                            DEFAULT_MAX_COLOR_TEMP)
        self.transition = self.args.get("transition", DEFAULT_TRANSITION)
        self.color_wheel = get_color_wheel(
            self.args.get("color_wheel", "default_color_wheel"))

        color_stepper = CircularStepper(0,
                                        len(self.color_wheel) - 1,
                                        len(self.color_wheel))
        self.manual_steppers: Dict[str, Stepper] = {
            LightController.ATTRIBUTE_BRIGHTNESS:
            MinMaxStepper(self.min_brightness, self.max_brightness,
                          manual_steps),
            LightController.ATTRIBUTE_WHITE_VALUE:
            MinMaxStepper(self.min_white_value, self.max_white_value,
                          manual_steps),
            LightController.ATTRIBUTE_COLOR_TEMP:
            MinMaxStepper(self.min_color_temp, self.max_color_temp,
                          manual_steps),
            LightController.ATTRIBUTE_XY_COLOR:
            color_stepper,
        }
        self.automatic_steppers: Dict[str, Stepper] = {
            LightController.ATTRIBUTE_BRIGHTNESS:
            MinMaxStepper(self.min_brightness, self.max_brightness,
                          automatic_steps),
            LightController.ATTRIBUTE_WHITE_VALUE:
            MinMaxStepper(self.min_white_value, self.max_white_value,
                          automatic_steps),
            LightController.ATTRIBUTE_COLOR_TEMP:
            MinMaxStepper(self.min_color_temp, self.max_color_temp,
                          automatic_steps),
            LightController.ATTRIBUTE_XY_COLOR:
            color_stepper,
        }
        self.smooth_power_on = self.args.get("smooth_power_on",
                                             self.supports_smooth_power_on())
        self.add_transition = self.args.get("add_transition",
                                            DEFAULT_ADD_TRANSITION)
        self.add_transition_turn_toggle = self.args.get(
            "add_transition_turn_toggle", DEFAULT_TRANSITION_TURN_TOGGLE)
        await super().init()
コード例 #3
0
    async def initialize(self) -> None:
        self.light = self.get_light(self.args["light"])
        await self.check_domain(self.light["name"])
        manual_steps = self.args.get("manual_steps", DEFAULT_MANUAL_STEPS)
        automatic_steps = self.args.get("automatic_steps", DEFAULT_AUTOMATIC_STEPS)
        self.min_brightness = self.args.get("min_brightness", DEFAULT_MIN_BRIGHTNESS)
        self.max_brightness = self.args.get("max_brightness", DEFAULT_MAX_BRIGHTNESS)
        self.min_white_value = self.args.get("min_white_value", DEFAULT_MIN_WHITE_VALUE)
        self.max_white_value = self.args.get("max_white_value", DEFAULT_MAX_WHITE_VALUE)
        self.min_color_temp = self.args.get("min_color_temp", DEFAULT_MIN_COLOR_TEMP)
        self.max_color_temp = self.args.get("max_color_temp", DEFAULT_MAX_COLOR_TEMP)
        self.transition = self.args.get("transition", DEFAULT_TRANSITION)
        self.color_wheel = get_color_wheel(
            self.args.get("color_wheel", "default_color_wheel")
        )

        color_stepper = CircularStepper(
            0, len(self.color_wheel) - 1, len(self.color_wheel)
        )
        self.manual_steppers: Dict[str, Stepper] = {
            LightController.ATTRIBUTE_BRIGHTNESS: MinMaxStepper(
                self.min_brightness, self.max_brightness, manual_steps
            ),
            LightController.ATTRIBUTE_WHITE_VALUE: MinMaxStepper(
                self.min_white_value, self.max_white_value, manual_steps
            ),
            LightController.ATTRIBUTE_COLOR_TEMP: MinMaxStepper(
                self.min_color_temp, self.max_color_temp, manual_steps
            ),
            LightController.ATTRIBUTE_XY_COLOR: color_stepper,
        }
        self.automatic_steppers: Dict[str, Stepper] = {
            LightController.ATTRIBUTE_BRIGHTNESS: MinMaxStepper(
                self.min_brightness, self.max_brightness, automatic_steps
            ),
            LightController.ATTRIBUTE_WHITE_VALUE: MinMaxStepper(
                self.min_white_value, self.max_white_value, automatic_steps
            ),
            LightController.ATTRIBUTE_COLOR_TEMP: MinMaxStepper(
                self.min_color_temp, self.max_color_temp, automatic_steps
            ),
            LightController.ATTRIBUTE_XY_COLOR: color_stepper,
        }
        self.smooth_power_on = self.args.get(
            "smooth_power_on", self.supports_smooth_power_on()
        )
        self.add_transition = self.args.get("add_transition", True)
        self.add_transition_turn_toggle = self.args.get(
            "add_transition_turn_toggle", False
        )
        update_supported_features = self.args.get("update_supported_features", False)

        self.supported_features = LightSupport(
            self.light["name"], self, update_supported_features
        )
        await super().initialize()
コード例 #4
0
    async def init(self) -> None:
        self.manual_steps = self.args.get("manual_steps", DEFAULT_MANUAL_STEPS)
        self.automatic_steps = self.args.get("automatic_steps",
                                             DEFAULT_AUTOMATIC_STEPS)

        self.min_max_attributes = {
            self.ATTRIBUTE_BRIGHTNESS:
            MinMax(
                self.args.get("min_brightness", DEFAULT_MIN_BRIGHTNESS),
                self.args.get("max_brightness", DEFAULT_MAX_BRIGHTNESS),
            ),
            self.ATTRIBUTE_WHITE_VALUE:
            MinMax(
                self.args.get("min_white_value", DEFAULT_MIN_WHITE_VALUE),
                self.args.get("max_white_value", DEFAULT_MAX_WHITE_VALUE),
            ),
            self.ATTRIBUTE_COLOR_TEMP:
            MinMax(
                self.args.get("min_color_temp", DEFAULT_MIN_COLOR_TEMP),
                self.args.get("max_color_temp", DEFAULT_MAX_COLOR_TEMP),
            ),
        }

        self.transition = self.args.get("transition", DEFAULT_TRANSITION)
        self.color_wheel = get_color_wheel(
            self.args.get("color_wheel", "default_color_wheel"))
        self._supported_color_modes = self.args.get("supported_color_modes")

        self.smooth_power_on = self.args.get("smooth_power_on",
                                             self.supports_smooth_power_on())
        self.add_transition = self.args.get("add_transition",
                                            DEFAULT_ADD_TRANSITION)
        self.add_transition_turn_toggle = self.args.get(
            "add_transition_turn_toggle", DEFAULT_TRANSITION_TURN_TOGGLE)
        self.hold_toggle_direction_init = self.get_option(
            self.args.get("hold_toggle_direction_init",
                          DEFAULT_HOLD_TOGGLE_DIRECTION_INIT),
            [StepperDir.UP, StepperDir.DOWN],
            "`hold_toggle_direction_init`",
        )
        await super().init()
コード例 #5
0
async def test_change_light_state(
    sut,
    mocker,
    monkeypatch,
    old,
    attribute,
    direction,
    stepper,
    light_state,
    smooth_power_on,
    expected_stop,
    expected_value_attribute,
):
    async def fake_get_entity_state(*args, **kwargs):
        return light_state

    called_service_patch = mocker.patch.object(sut, "call_service")
    sut.smooth_power_on = smooth_power_on
    sut.value_attribute = old
    sut.manual_steppers = {attribute: stepper}
    sut.automatic_steppers = {attribute: stepper}
    sut.transition = 300
    sut.add_transition = True
    sut.add_transition_turn_toggle = False
    sut.supported_features = LightSupport(None, None, False)
    sut.supported_features._supported_features = set()
    sut.color_wheel = get_color_wheel("default_color_wheel")

    monkeypatch.setattr(sut, "get_entity_state", fake_get_entity_state)

    # SUT
    stop = await sut.change_light_state(old, attribute, direction, stepper,
                                        "hold")

    # Checks
    assert stop == expected_stop
    assert sut.value_attribute == expected_value_attribute
    called_service_patch.assert_called()
コード例 #6
0
def test_get_color_wheel(colors: Colors, error_expected: bool):
    with wrap_exetuction(error_expected=error_expected, exception=ValueError):
        colors = get_color_wheel(colors)