Ejemplo n.º 1
0
def test_config_google_home_entity_id_to_number_empty():
    """Test config adheres to the type."""
    mock_hass = Mock()
    mock_hass.config.path = MagicMock("path", return_value="test_path")
    conf = Config(mock_hass, {"type": "google_home"})

    with patch(
        "homeassistant.components.emulated_hue.load_json", return_value={}
    ) as json_loader, patch(
        "homeassistant.components.emulated_hue.save_json"
    ) as json_saver:
        number = conf.entity_id_to_number("light.test")
        assert number == "1"
        assert json_saver.call_count == 1
        assert json_loader.call_count == 1

        assert json_saver.mock_calls[0][1][1] == {"1": "light.test"}

        number = conf.entity_id_to_number("light.test")
        assert number == "1"
        assert json_saver.call_count == 1

        number = conf.entity_id_to_number("light.test2")
        assert number == "2"
        assert json_saver.call_count == 2

        entity_id = conf.number_to_entity_id("2")
        assert entity_id == "light.test2"
Ejemplo n.º 2
0
def test_config_google_home_entity_id_to_number():
    """Test config adheres to the type."""
    conf = Config(Mock(), {
        'type': 'google_home'
    })

    mop = mock_open(read_data=json.dumps({'1': 'light.test2'}))
    handle = mop()

    with patch('homeassistant.components.emulated_hue.open', mop, create=True):
        number = conf.entity_id_to_number('light.test')
        assert number == '2'
        assert handle.write.call_count == 1
        assert json.loads(handle.write.mock_calls[0][1][0]) == {
            '1': 'light.test2',
            '2': 'light.test',
        }

        number = conf.entity_id_to_number('light.test')
        assert number == '2'
        assert handle.write.call_count == 1

        number = conf.entity_id_to_number('light.test2')
        assert number == '1'
        assert handle.write.call_count == 1

        entity_id = conf.number_to_entity_id('1')
        assert entity_id == 'light.test2'
Ejemplo n.º 3
0
async def test_config_google_home_entity_id_to_number_altered(hass, hass_storage):
    """Test config adheres to the type."""
    conf = Config(hass, {"type": "google_home"})
    hass_storage[DATA_KEY] = {
        "version": DATA_VERSION,
        "key": DATA_KEY,
        "data": {"21": "light.test2"},
    }

    await conf.async_setup()

    number = conf.entity_id_to_number("light.test")
    assert number == "22"

    async_fire_time_changed(hass, utcnow() + timedelta(seconds=SAVE_DELAY))
    await hass.async_block_till_done()
    assert hass_storage[DATA_KEY]["data"] == {
        "21": "light.test2",
        "22": "light.test",
    }

    number = conf.entity_id_to_number("light.test")
    assert number == "22"

    number = conf.entity_id_to_number("light.test2")
    assert number == "21"

    entity_id = conf.number_to_entity_id("21")
    assert entity_id == "light.test2"
Ejemplo n.º 4
0
def test_config_google_home_entity_id_to_number_empty():
    """Test config adheres to the type."""
    mock_hass = Mock()
    mock_hass.config.path = MagicMock("path", return_value="test_path")
    conf = Config(mock_hass, {'type': 'google_home'})

    with patch('homeassistant.components.emulated_hue.load_json',
               return_value={}) as json_loader:
        with patch('homeassistant.components.emulated_hue'
                   '.save_json') as json_saver:
            number = conf.entity_id_to_number('light.test')
            assert number == '1'
            assert json_saver.call_count == 1
            assert json_loader.call_count == 1

            assert json_saver.mock_calls[0][1][1] == {
                '1': 'light.test',
            }

            number = conf.entity_id_to_number('light.test')
            assert number == '1'
            assert json_saver.call_count == 1

            number = conf.entity_id_to_number('light.test2')
            assert number == '2'
            assert json_saver.call_count == 2

            entity_id = conf.number_to_entity_id('2')
            assert entity_id == 'light.test2'
Ejemplo n.º 5
0
def test_config_google_home_entity_id_to_number():
    """Test config adheres to the type."""
    conf = Config(Mock(), {'type': 'google_home'})

    mop = mock_open(read_data=json.dumps({'1': 'light.test2'}))
    handle = mop()

    with patch('homeassistant.components.emulated_hue.open', mop, create=True):
        number = conf.entity_id_to_number('light.test')
        assert number == '2'
        assert handle.write.call_count == 1
        assert json.loads(handle.write.mock_calls[0][1][0]) == {
            '1': 'light.test2',
            '2': 'light.test',
        }

        number = conf.entity_id_to_number('light.test')
        assert number == '2'
        assert handle.write.call_count == 1

        number = conf.entity_id_to_number('light.test2')
        assert number == '1'
        assert handle.write.call_count == 1

        entity_id = conf.number_to_entity_id('1')
        assert entity_id == 'light.test2'
Ejemplo n.º 6
0
def test_config_google_home_entity_id_to_number_empty():
    """Test config adheres to the type."""
    mock_hass = Mock()
    mock_hass.config.path = MagicMock("path", return_value="test_path")
    conf = Config(mock_hass, {
        'type': 'google_home'
    })

    with patch('homeassistant.components.emulated_hue.load_json',
               return_value={}) as json_loader:
        with patch('homeassistant.components.emulated_hue'
                   '.save_json') as json_saver:
            number = conf.entity_id_to_number('light.test')
            assert number == '1'
            assert json_saver.call_count == 1
            assert json_loader.call_count == 1

            assert json_saver.mock_calls[0][1][1] == {
                '1': 'light.test',
            }

            number = conf.entity_id_to_number('light.test')
            assert number == '1'
            assert json_saver.call_count == 1

            number = conf.entity_id_to_number('light.test2')
            assert number == '2'
            assert json_saver.call_count == 2

            entity_id = conf.number_to_entity_id('2')
            assert entity_id == 'light.test2'
Ejemplo n.º 7
0
def test_config_google_home_entity_id_to_number():
    """Test config adheres to the type."""
    mock_hass = Mock()
    mock_hass.config.path = MagicMock("path", return_value="test_path")
    conf = Config(mock_hass, {
        'type': 'google_home'
    })

    mop = mock_open(read_data=json.dumps({'1': 'light.test2'}))
    handle = mop()

    with patch('homeassistant.util.json.open', mop, create=True):
        with patch('homeassistant.util.json.os.open', return_value=0):
            with patch('homeassistant.util.json.os.replace'):
                number = conf.entity_id_to_number('light.test')
                assert number == '2'
                assert handle.write.call_count == 1
                assert json.loads(handle.write.mock_calls[0][1][0]) == {
                    '1': 'light.test2',
                    '2': 'light.test',
                }

                number = conf.entity_id_to_number('light.test')
                assert number == '2'
                assert handle.write.call_count == 1

                number = conf.entity_id_to_number('light.test2')
                assert number == '1'
                assert handle.write.call_count == 1

                entity_id = conf.number_to_entity_id('1')
                assert entity_id == 'light.test2'
Ejemplo n.º 8
0
def test_config_alexa_entity_id_to_number():
    """Test config adheres to the type."""
    conf = Config(None, {"type": "alexa"})

    number = conf.entity_id_to_number("light.test")
    assert number == "light.test"

    number = conf.entity_id_to_number("light.test")
    assert number == "light.test"

    number = conf.entity_id_to_number("light.test2")
    assert number == "light.test2"

    entity_id = conf.number_to_entity_id("light.test")
    assert entity_id == "light.test"
Ejemplo n.º 9
0
def test_config_alexa_entity_id_to_number():
    """Test config adheres to the type."""
    conf = Config(None, {'type': 'alexa'})

    number = conf.entity_id_to_number('light.test')
    assert number == 'light.test'

    number = conf.entity_id_to_number('light.test')
    assert number == 'light.test'

    number = conf.entity_id_to_number('light.test2')
    assert number == 'light.test2'

    entity_id = conf.number_to_entity_id('light.test')
    assert entity_id == 'light.test'
Ejemplo n.º 10
0
def test_config_google_home_entity_id_to_number():
    """Test config adheres to the type."""
    conf = Config({"type": "google_home"})

    number = conf.entity_id_to_number("light.test")
    assert number == "1"

    number = conf.entity_id_to_number("light.test")
    assert number == "1"

    number = conf.entity_id_to_number("light.test2")
    assert number == "2"

    entity_id = conf.number_to_entity_id("1")
    assert entity_id == "light.test"
Ejemplo n.º 11
0
def test_config_alexa_entity_id_to_number():
    """Test config adheres to the type."""
    conf = Config({"type": "alexa"})

    number = conf.entity_id_to_number("light.test")
    assert number == "light.test"

    number = conf.entity_id_to_number("light.test")
    assert number == "light.test"

    number = conf.entity_id_to_number("light.test2")
    assert number == "light.test2"

    entity_id = conf.number_to_entity_id("light.test")
    assert entity_id == "light.test"
Ejemplo n.º 12
0
def test_config_google_home_entity_id_to_number():
    """Test config adheres to the type."""
    conf = Config({'type': 'google_home'})

    number = conf.entity_id_to_number('light.test')
    assert number == '1'

    number = conf.entity_id_to_number('light.test')
    assert number == '1'

    number = conf.entity_id_to_number('light.test2')
    assert number == '2'

    entity_id = conf.number_to_entity_id('1')
    assert entity_id == 'light.test'
Ejemplo n.º 13
0
def test_config_alexa_entity_id_to_number():
    """Test config adheres to the type."""
    conf = Config(None, {
        'type': 'alexa'
    })

    number = conf.entity_id_to_number('light.test')
    assert number == 'light.test'

    number = conf.entity_id_to_number('light.test')
    assert number == 'light.test'

    number = conf.entity_id_to_number('light.test2')
    assert number == 'light.test2'

    entity_id = conf.number_to_entity_id('light.test')
    assert entity_id == 'light.test'
Ejemplo n.º 14
0
def test_config_google_home_entity_id_to_number():
    """Test config adheres to the type."""
    conf = Config({
        'type': 'google_home'
    })

    number = conf.entity_id_to_number('light.test')
    assert number == '1'

    number = conf.entity_id_to_number('light.test')
    assert number == '1'

    number = conf.entity_id_to_number('light.test2')
    assert number == '2'

    entity_id = conf.number_to_entity_id('1')
    assert entity_id == 'light.test'