示例#1
0
def dict_to_load(load_dict, raise_exception=True):
    """Get a Python object of any Load from a dictionary.

    Args:
        load_dict: A dictionary of any Honeybee energy load. 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 load. Default: True.

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

    if load_type == 'People':
        return People.from_dict(load_dict)
    elif load_type == 'Lighting':
        return Lighting.from_dict(load_dict)
    elif load_type == 'ElectricEquipment':
        return ElectricEquipment.from_dict(load_dict)
    elif load_type == 'GasEquipment':
        return GasEquipment.from_dict(load_dict)
    elif load_type == 'Infiltration':
        return Infiltration.from_dict(load_dict)
    elif load_type == 'Ventilation':
        return Ventilation.from_dict(load_dict)
    elif load_type == 'Setpoint':
        return Setpoint.from_dict(load_dict)
    elif raise_exception:
        raise ValueError(
            '{} is not a recognized energy Load type'.format(load_type))
示例#2
0
def test_setpoint_dict_methods():
    """Test the to/from dict methods."""
    simple_heat = ScheduleDay(
        'Simple Weekday HtgSetp', [18, 21, 18],
        [Time(0, 0), Time(9, 0), Time(17, 0)])
    simple_cool = ScheduleDay(
        'Simple Weekday ClgSetp', [28, 24, 28],
        [Time(0, 0), Time(9, 0), Time(17, 0)])
    heat_setpt = ScheduleRuleset('Office Heating', simple_heat, None,
                                 schedule_types.temperature)
    cool_setpt = ScheduleRuleset('Office Cooling', simple_cool, None,
                                 schedule_types.temperature)
    humid_setpt = ScheduleRuleset.from_constant_value('Office Humid', 30,
                                                      schedule_types.humidity)
    dehumid_setpt = ScheduleRuleset.from_constant_value(
        'Office Dehumid', 60, schedule_types.humidity)
    setpoint = Setpoint('Office Setpoint', heat_setpt, cool_setpt, humid_setpt,
                        dehumid_setpt)

    setp_dict = setpoint.to_dict()
    new_setpoint = Setpoint.from_dict(setp_dict)
    assert new_setpoint == setpoint
    assert setp_dict == new_setpoint.to_dict()