async def test_hold( sut: LightController, monkeypatch: MonkeyPatch, mocker: MockerFixture, attribute_input: str, direction_input: str, previous_direction: str, light_state: Literal["on", "off"], smooth_power_on: bool, expected_calls: int, expected_direction: str, ): value_attribute = 10 monkeypatch.setattr(sut, "get_entity_state", fake_fn(to_return=light_state, async_=True)) monkeypatch.setattr(sut, "get_value_attribute", fake_fn(to_return=value_attribute, async_=True)) monkeypatch.setattr(sut, "get_attribute", fake_fn(to_return=attribute_input, async_=True)) sut.smooth_power_on = smooth_power_on sut.feature_support._supported_features = 0 stepper = MinMaxStepper(1, 10, 10) stepper.previous_direction = previous_direction sut.automatic_steppers = {attribute_input: stepper} super_hold_patch = mocker.patch.object(ReleaseHoldController, "hold") await sut.hold(attribute_input, direction_input) assert super_hold_patch.call_count == expected_calls if expected_calls > 0: super_hold_patch.assert_called_with(attribute_input, expected_direction)
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_click( sut: LightController, monkeypatch: MonkeyPatch, mocker: MockerFixture, attribute_input: str, direction_input: Literal["up", "down"], light_state: Literal["on", "off"], smooth_power_on: bool, expected_calls: int, ): value_attribute = 10 monkeypatch.setattr(sut, "get_entity_state", fake_fn(to_return=light_state, async_=True)) monkeypatch.setattr(sut, "get_value_attribute", fake_fn(to_return=value_attribute, async_=True)) monkeypatch.setattr(sut, "get_attribute", fake_fn(to_return=attribute_input, async_=True)) change_light_state_patch = mocker.patch.object(sut, "change_light_state") sut.smooth_power_on = smooth_power_on sut.feature_support._supported_features = 0 stepper = MinMaxStepper(1, 10, 10) sut.manual_steppers = {attribute_input: stepper} await sut.click(attribute_input, direction_input) assert change_light_state_patch.call_count == expected_calls
async def test_get_value_attribute( sut: LightController, monkeypatch: MonkeyPatch, attribute_input: str, direction_input: Literal["up", "down"], light_state: str, expected_output: Union[int, float, str], error_expected: bool, ): sut.smooth_power_on = True 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, direction_input) if not error_expected: assert output == float(expected_output)