async def test_sync( sut: LightController, monkeypatch: MonkeyPatch, mocker: MockerFixture, max_brightness: int, color_attribute: str, expected_attributes: Dict[str, Any], ): sut.max_brightness = max_brightness sut.add_transition_turn_toggle = True sut.feature_support._supported_features = LightSupport.TRANSITION async def fake_get_attribute(*args, **kwargs): if color_attribute == "error": raise ValueError() return color_attribute monkeypatch.setattr(sut, "get_attribute", fake_get_attribute) monkeypatch.setattr(sut, "get_entity_state", fake_fn(async_=True, to_return="on")) called_service_patch = mocker.patch.object(sut, "call_service") await sut.sync() called_service_patch.assert_called_once_with("light/turn_on", entity_id=ENTITY_NAME, **{ "transition": 0.3, **expected_attributes })
async def test_check_remove_transition( sut: LightController, add_transition: bool, add_transition_turn_toggle: bool, on_from_user: bool, transition_support: bool, expected_remove_transition_check: bool, ): sut.transition = 300 sut.add_transition = add_transition sut.add_transition_turn_toggle = add_transition_turn_toggle sut.feature_support._supported_features = (LightSupport.TRANSITION if transition_support else 0) output = await sut.check_remove_transition(on_from_user) assert output == expected_remove_transition_check
async def test_call_light_service( sut: LightController, mocker: MockerFixture, attributes_input: Dict[str, str], transition_support: bool, turned_toggle: bool, add_transition: bool, add_transition_turn_toggle: bool, attributes_expected: Dict[str, str], ): called_service_patch = mocker.patch.object(sut, "call_service") sut.transition = 300 sut.add_transition = add_transition sut.add_transition_turn_toggle = add_transition_turn_toggle sut.feature_support._supported_features = ( LightSupport.TRANSITION if transition_support else 0 ) await sut.call_light_service( "test_service", turned_toggle=turned_toggle, **attributes_input ) called_service_patch.assert_called_once_with( "test_service", entity_id=ENTITY_NAME, **attributes_expected )