Beispiel #1
0
def test_fetch_scenes(monkeypatch):
    test_scene_name = 'test scene'

    class MockResponse:
        def json(self):
            return {
                '1': {
                    'name': test_scene_name,
                    'lights': [1],
                },
                '2': {
                    'name': test_scene_name,
                    'lights': [2]
                }
            }

    test_url = 'http://test.com'

    def mock_get(*args, **kwargs):
        assert args[0] == test_url + '/scenes'
        return MockResponse()

    monkeypatch.setattr(requests, 'get', mock_get)
    api = HueApi()
    api.lights = [
        HueLight(1, 'Light 1', {}, None),
        HueLight(2, 'light 2', {}, None)
    ]
    api.base_url = test_url
    api.fetch_scenes()
    assert len(api.scenes) == 2
    assert len(api.grouped_scenes) == 1
    assert len(api.scenes[0].lights) == 1
    assert len(api.scenes[1].lights) == 1
    assert len(api.grouped_scenes[test_scene_name]) == 2
Beispiel #2
0
def test_fetch_groups(monkeypatch):
    test_group_name = 'test group'

    class MockResponse:
        def json(self):
            return {
                '1': {
                    'name': test_group_name,
                    'lights': [2],
                }
            }

    test_url = 'http://test.com'

    def mock_get(*args, **kwargs):
        assert args[0] == test_url + '/groups'
        return MockResponse()

    monkeypatch.setattr(requests, 'get', mock_get)
    api = HueApi()
    api.lights = [
        HueLight(1, 'Light 1', {}, None),
        HueLight(2, 'light 2', {}, None)
    ]
    api.base_url = test_url
    api.fetch_groups()
    assert len(api.groups) == 1
    assert api.groups[0].id == '1'
    assert len(api.groups[0].lights) == 1
    assert api.groups[0].lights[0].id == 2
    assert api.groups[0].name == test_group_name
Beispiel #3
0
def test_set_brightness(put_nothing):
    api = HueApi()
    api.lights = [
        HueLight(1, 'Light 1', {'bri': 1}, None),
    ]
    light = api.lights[0]
    assert light.state.brightness == 1
    api.set_brightness(100)
    assert light.state.brightness == 100
    api.set_brightness('max')
    assert light.state.brightness == 254
Beispiel #4
0
def test_toggle_on(put_nothing):
    api = HueApi()
    api.lights = [
        HueLight(1, 'Light 1', {'on': False}, None),
    ]
    light = api.lights[0]
    assert not light.state.is_on
    api.toggle_on()
    assert light.state.is_on
    api.toggle_on()
    assert not light.state.is_on
Beispiel #5
0
def test_filter_lights():
    api = HueApi()
    api.lights = [
        HueLight(1, 'Light 1', {}, None),
        HueLight(2, 'light 2', {}, None)
    ]
    assert len(api.filter_lights(None)) == 2
    assert len(api.filter_lights([1])) == 1
    assert api.filter_lights([1])[0].id == 1
    assert api.filter_lights([2])[0].id == 2
    assert api.filter_lights([1, 2]) == api.lights
Beispiel #6
0
def test_turn_on_off(put_nothing):
    api = HueApi()
    api.lights = [
        HueLight(1, 'Light 1', {}, None),
        HueLight(2, 'light 2', {}, None)
    ]
    for light in api.lights:
        assert not light.state.is_on
    api.turn_on()
    for light in api.lights:
        assert light.state.is_on
    api.turn_off([1])
    assert not api.lights[0].state.is_on
    assert api.lights[1].state.is_on
Beispiel #7
0
def test_set_color(put_nothing):
    api = HueApi()
    api.lights = [
        HueLight(1, 'Light 1', {'hue': 0, 'sat': 0}, None),
    ]
    light = api.lights[0]
    assert light.state.hue == 0
    assert light.state.saturation == 0
    api.set_color('red')
    assert light.state.hue == 0
    assert light.state.saturation == 255
    api.set_color('green')
    assert light.state.hue == 21845
    assert light.state.saturation == 255