async def test_change_light_state( sut: LightController, mocker: MockerFixture, old: int, attribute: str, direction: Literal["up", "down"], stepper: MinMaxStepper, smooth_power_on_check: bool, stop_expected: bool, expected_value_attribute: int, ): called_service_patch = mocker.patch.object(sut, "call_service") sut.value_attribute = old sut.smooth_power_on_check = smooth_power_on_check sut.remove_transition_check = False sut.manual_steppers = {attribute: stepper} sut.automatic_steppers = {attribute: stepper} sut.feature_support._supported_features = 0 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_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_get_value_attribute( sut: LightController, monkeypatch: MonkeyPatch, attribute_input: str, smooth_power_on_check: bool, light_state: str, expected_output: Union[int, float, str], error_expected: bool, ): sut.smooth_power_on = True sut.smooth_power_on_check = smooth_power_on_check async def fake_get_entity_state(entity, attribute=None): if entity == "light" and attribute is None: return light_state return expected_output monkeypatch.setattr(sut, "get_entity_state", fake_get_entity_state) with wrap_exetuction(error_expected=error_expected, exception=ValueError): output = await sut.get_value_attribute(attribute_input) if not error_expected: assert output == float(expected_output)