async def test_change_light_state( sut: LightController, mocker: MockerFixture, monkeypatch: MonkeyPatch, old: int, attribute: str, direction: Literal["up", "down"], stepper: MinMaxStepper, light_state: str, smooth_power_on: bool, stop_expected: bool, expected_value_attribute: int, ): 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.feature_support._supported_features = 0 monkeypatch.setattr( sut, "get_entity_state", fake_fn(to_return=light_state, async_=True) ) stop = await sut.change_light_state(old, attribute, direction, stepper, "hold") assert stop == stop_expected assert sut.value_attribute == expected_value_attribute called_service_patch.assert_called()
async def test_on_min(sut: LightController, mocker: MockerFixture): attribute = "test_attribute" min_ = 1 on_patch = mocker.patch.object(sut, "_on") stepper = MinMaxStepper(min_, 10, 10) sut.automatic_steppers = {attribute: stepper} await sut.on_min(attribute) on_patch.assert_called_once_with(**{attribute: min_})
async def test_on_full(sut: LightController, mocker: MockerFixture): attribute = "test_attribute" max_ = 10 on_patch = mocker.patch.object(sut, "on") stepper = MinMaxStepper(1, max_, 10) sut.automatic_steppers = {attribute: stepper} await sut.on_full(attribute, light_on=False) on_patch.assert_called_once_with(light_on=False, **{attribute: max_})
async def test_toggle_min( sut: LightController, mocker: MockerFixture, attribute: str, stepper: MinMaxStepper, expected_attribute_value: int, ): call_service_patch = mocker.patch.object(sut, "call_service") sut.automatic_steppers = {attribute: stepper} await sut.toggle_min(attribute) call_service_patch.assert_called_once_with( "light/toggle", **{"entity_id": ENTITY_NAME, attribute: expected_attribute_value} )
async def test_hold_loop(sut: LightController, mocker: MockerFixture, value_attribute: int): attribute = "test_attribute" direction = Stepper.UP sut.smooth_power_on_check = False sut.value_attribute = value_attribute change_light_state_patch = mocker.patch.object(sut, "change_light_state") stepper = MinMaxStepper(1, 10, 10) sut.automatic_steppers = {attribute: stepper} exceeded = await sut.hold_loop(attribute, direction) if value_attribute is None: assert exceeded else: change_light_state_patch.assert_called_once_with( sut.value_attribute, attribute, direction, stepper, "hold")
async def test_set_value( sut: LightController, mocker: MockerFixture, stepper_cls: Type[Union[MinMaxStepper, CircularStepper]], min_max: Tuple[int, int], fraction: float, expected_calls: int, expected_value: int, ): attribute = "test_attribute" on_patch = mocker.patch.object(sut, "_on") stepper = stepper_cls(min_max[0], min_max[1], 1) sut.automatic_steppers = {attribute: stepper} await sut.set_value(attribute, fraction) assert on_patch.call_count == expected_calls if expected_calls > 0: on_patch.assert_called_with(**{attribute: expected_value})