Esempio n. 1
0
async def test_sync(sut, monkeypatch, mocker, max_brightness, color_attribute,
                    expected_attributes):
    sut.max_brightness = max_brightness
    sut.light = {"name": "test_light"}
    sut.transition = 300
    sut.add_transition = True
    sut.add_transition_turn_toggle = True
    sut.supported_features = LightSupport(
        FeatureSupport.encode({LightSupport.TRANSITION}))

    def fake_get_attribute(*args, **kwargs):
        if color_attribute == "error":
            raise ValueError()
        return color_attribute

    monkeypatch.setattr(sut, "get_attribute", fake_get_attribute)
    called_service_patch = mocker.patch.object(sut, "call_service")

    await sut.sync()

    called_service_patch.assert_called_once_with("light/turn_on",
                                                 entity_id="test_light",
                                                 **{
                                                     "transition": 0.3,
                                                     **expected_attributes
                                                 })
async def test_close(sut, mocker, supported_features, expected_service):
    sut.supported_features = CoverSupport(
        FeatureSupport.encode(supported_features))
    called_service_patch = mocker.patch.object(sut, "call_service")
    await sut.close()
    if expected_service is not None:
        if expected_service == "cover/close_cover":
            expected_attributes = {"entity_id": "cover.test"}
        elif expected_service == "cover/set_cover_position":
            expected_attributes = {"entity_id": "cover.test", "position": 0}
        else:
            expected_attributes = {}
        called_service_patch.assert_called_once_with(expected_service,
                                                     **expected_attributes)
    else:
        assert called_service_patch.call_count == 0
Esempio n. 3
0
def test_get_attribute(
    sut,
    monkeypatch,
    attribute_input,
    color_mode,
    supported_features,
    attribute_expected,
    throws_error,
):
    sut.supported_features = LightSupport(
        FeatureSupport.encode(supported_features))
    sut.light = {"name": "light", "color_mode": color_mode}

    # SUT
    if throws_error:
        with pytest.raises(ValueError) as e:
            sut.get_attribute(attribute_input)
    else:
        output = sut.get_attribute(attribute_input)

        # Checks
        assert output == attribute_expected
Esempio n. 4
0
async def test_call_light_service(
    sut,
    mocker,
    attributes_input,
    transition_support,
    turned_toggle,
    add_transition,
    add_transition_turn_toggle,
    attributes_expected,
):
    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
    supported_features = {LightSupport.TRANSITION
                          } if transition_support else set()
    sut.supported_features = LightSupport(
        FeatureSupport.encode(supported_features))
    await sut.call_light_service("test_service",
                                 turned_toggle=turned_toggle,
                                 **attributes_input)
    called_service_patch.assert_called_once_with("test_service",
                                                 entity_id=sut.light["name"],
                                                 **attributes_expected)
def test_init(number, expected_supported_features):
    media_player_support = MediaPlayerSupport(None, None)
    media_player_support._supported_features = FeatureSupport.decode(
        number, media_player_support.features)
    assert media_player_support._supported_features == expected_supported_features
Esempio n. 6
0
def test_init(number, expected_supported_features):
    light_support = LightSupport(None, None)
    light_support._supported_features = FeatureSupport.decode(
        number, light_support.features)
    assert light_support._supported_features == expected_supported_features
Esempio n. 7
0
def test_not_supported(number, features, feature, is_supported):
    feature_support = FeatureSupport(number, features)
    is_supported = feature_support.is_supported(feature)
    assert is_supported == is_supported
Esempio n. 8
0
def test_init(number, features, expected_features):
    feature_support = FeatureSupport(number, features)
    assert feature_support.supported_features == expected_features
Esempio n. 9
0
def test_encode(supported_features, expected_number):
    number = FeatureSupport.encode(supported_features)
    assert expected_number == number
Esempio n. 10
0
def test_decode(number, features, expected_features):
    supported_features = FeatureSupport.decode(number, features)
    assert supported_features == expected_features
Esempio n. 11
0
async def test_not_supported(number, features, feature, is_supported):
    feature_support = FeatureSupport(None, None, features)
    feature_support._supported_features = FeatureSupport.decode(
        number, features)
    is_supported = await feature_support.not_supported(feature)
    assert is_supported == is_supported
Esempio n. 12
0
def test_init(number, expected_supported_features):
    cover_support = CoverSupport(None, None)
    cover_support._supported_features = FeatureSupport.decode(
        number, cover_support.features)
    assert cover_support._supported_features == expected_supported_features