Example #1
0
def dict_to_construction(constr_dict, raise_exception=True):
    """Get a Python object of any Construction from a dictionary.

    Args:
        constr_dict: A dictionary of any Honeybee energy construction. Note
            that this should be a non-abridged dictionary to be valid.
        raise_exception: Boolean to note whether an excpetion should be raised
            if the object is not identified as a construction. Default: True.

    Returns:
        A Python object derived from the input constr_dict.
    """
    try:  # get the type key from the dictionary
        constr_type = constr_dict['type']
    except KeyError:
        raise ValueError('Construction dictionary lacks required "type" key.')

    if constr_type == 'OpaqueConstruction':
        return OpaqueConstruction.from_dict(constr_dict)
    elif constr_type == 'WindowConstruction':
        return WindowConstruction.from_dict(constr_dict)
    elif constr_type == 'WindowConstructionShade':
        return WindowConstructionShade.from_dict(constr_dict)
    elif constr_type == 'ShadeConstruction':
        return ShadeConstruction.from_dict(constr_dict)
    elif constr_type == 'AirBoundaryConstruction':
        return AirBoundaryConstruction.from_dict(constr_dict)
    elif raise_exception:
        raise ValueError(
            '{} is not a recognized energy Construction type'.format(
                constr_type))
Example #2
0
def test_window_dict_methods():
    """Test the to/from dict methods."""
    clear_glass = EnergyWindowMaterialGlazing(
        'Clear Glass', 0.005715, 0.770675, 0.07, 0.8836, 0.0804,
        0, 0.84, 0.84, 1.0)
    gap = EnergyWindowMaterialGas('air gap', thickness=0.0127)
    triple_clear = WindowConstruction(
        'Triple Clear Window', [clear_glass, gap, clear_glass, gap, clear_glass])
    constr_dict = triple_clear.to_dict()
    new_constr = WindowConstruction.from_dict(constr_dict)
    assert constr_dict == new_constr.to_dict()
Example #3
0
def test_construction_from_lib():
    """Test the existence of construction objects in the library."""
    runner = CliRunner()

    result = runner.invoke(opaque_material_by_id, ['Generic Gypsum Board'])
    assert result.exit_code == 0
    mat_dict = json.loads(result.output)
    assert isinstance(EnergyMaterial.from_dict(mat_dict), EnergyMaterial)

    result = runner.invoke(window_material_by_id, ['Generic Low-e Glass'])
    assert result.exit_code == 0
    mat_dict = json.loads(result.output)
    assert isinstance(EnergyWindowMaterialGlazing.from_dict(mat_dict),
                      EnergyWindowMaterialGlazing)

    result = runner.invoke(opaque_construction_by_id,
                           ['Generic Exterior Wall'])
    assert result.exit_code == 0
    con_dict = json.loads(result.output)
    assert isinstance(OpaqueConstruction.from_dict(con_dict),
                      OpaqueConstruction)

    result = runner.invoke(window_construction_by_id, ['Generic Double Pane'])
    assert result.exit_code == 0
    con_dict = json.loads(result.output)
    assert isinstance(WindowConstruction.from_dict(con_dict),
                      WindowConstruction)

    result = runner.invoke(shade_construction_by_id, ['Generic Context'])
    assert result.exit_code == 0
    mat_dict = json.loads(result.output)
    assert isinstance(ShadeConstruction.from_dict(mat_dict), ShadeConstruction)

    result = runner.invoke(construction_set_by_id,
                           ['Default Generic Construction Set'])
    assert result.exit_code == 0
    con_dict = json.loads(result.output)
    assert isinstance(ConstructionSet.from_dict(con_dict), ConstructionSet)