Skip to content

Commit

Permalink
fix(air): Support AirBoundary Constructions
Browse files Browse the repository at this point in the history
- Add new AirBoundary Properties
- Update Tests
  • Loading branch information
ed-p-may committed Nov 10, 2024
1 parent 225e0b9 commit 232e964
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 2 deletions.
10 changes: 10 additions & 0 deletions honeybee_energy_ph/_extend_honeybee_energy_ph.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
EnergyMaterialVegetationProperties,
LightingProperties,
OpaqueConstructionProperties,
AirBoundaryConstructionProperties,
PeopleProperties,
ServiceHotWaterProperties,
WindowConstructionProperties,
Expand All @@ -27,6 +28,7 @@
from honeybee_energy.schedule.ruleset import ScheduleRulesetProperties

from honeybee_energy_ph.properties.construction.opaque import OpaqueConstructionPhProperties
from honeybee_energy_ph.properties.construction.air import AirBoundaryConstructionPhProperties
from honeybee_energy_ph.properties.construction.window import WindowConstructionPhProperties
from honeybee_energy_ph.properties.construction.windowshade import WindowConstructionShadePhProperties
from honeybee_energy_ph.properties.hot_water.hw_program import ServiceHotWaterPhProperties
Expand Down Expand Up @@ -55,6 +57,7 @@
setattr(SpaceProperties, "_energy", None)
setattr(ScheduleRulesetProperties, "_ph", None)
setattr(OpaqueConstructionProperties, "_ph", None)
setattr(AirBoundaryConstructionProperties, "_ph", None)
setattr(EnergyMaterialProperties, "_ph", None)
setattr(EnergyMaterialNoMassProperties, "_ph", None)
setattr(EnergyMaterialVegetationProperties, "_ph", None)
Expand Down Expand Up @@ -90,6 +93,12 @@ def opaque_construction_ph_properties(self):
return self._ph


def air_boundary_construction_ph_properties(self):
if self._ph is None:
self._ph = AirBoundaryConstructionPhProperties()
return self._ph


def energy_material_ph_properties(self):
if self._ph is None:
self._ph = EnergyMaterialPhProperties()
Expand Down Expand Up @@ -151,6 +160,7 @@ def lighting_ph_properties(self):
setattr(SpaceProperties, "energy", property(space_energy_properties))
setattr(ScheduleRulesetProperties, "ph", property(schedule_ruleset_ph_properties))
setattr(OpaqueConstructionProperties, "ph", property(opaque_construction_ph_properties))
setattr(AirBoundaryConstructionProperties, "ph", property(air_boundary_construction_ph_properties))
setattr(WindowConstructionProperties, "ph", property(window_construction_ph_properties))
setattr(
WindowConstructionShadeProperties,
Expand Down
73 changes: 73 additions & 0 deletions honeybee_energy_ph/properties/construction/air.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*-
# -*- Python Version: 2.7 -*-

"""Passive House properties for honeybee_energy.construction.air.AirBoundaryConstruction Objects"""

try:
from typing import Any
except ImportError:
pass # Python 2.7


class AirBoundaryConstructionPhProperties_FromDictError(Exception):
def __init__(self, _expected_types, _input_type):
self.msg = 'Error: Expected type of "{}". Got: {}'.format(_expected_types, _input_type)
super(AirBoundaryConstructionPhProperties_FromDictError, self).__init__(self.msg)


class AirBoundaryConstructionPhProperties(object):
def __init__(self, _host=None):
# type (Any) -> None
self._host = _host
self.id_num = 0

@property
def host(self):
return self._host

def duplicate(self, new_host=None):
# type: (Any) -> AirBoundaryConstructionPhProperties
return self.__copy__(new_host)

def __copy__(self, new_host=None):
# type: (Any) -> AirBoundaryConstructionPhProperties
host = new_host or self.host

new_obj = self.__class__(host)
new_obj.id_num = self.id_num
return new_obj

def to_dict(self, abridged=False):
# type: (bool) -> dict
d = {}

if abridged:
d["type"] = "AirBoundaryConstructionPhPropertiesAbridged"
else:
d["type"] = "AirBoundaryConstructionPhProperties"

d["id_num"] = self.id_num
return {"ph": d}

@classmethod
def from_dict(cls, _input_dict, host):
# type: (dict, Any) -> AirBoundaryConstructionPhProperties
valid_types = (
"AirBoundaryConstructionPhProperties",
"AirBoundaryConstructionPhPropertiesAbridged",
)
if _input_dict["type"] not in valid_types:
raise AirBoundaryConstructionPhProperties_FromDictError(valid_types, _input_dict["type"])

new_obj = cls(host)
new_obj.id_num = _input_dict["id_num"]
return new_obj

def __str__(self):
return "{}(id_num={!r})".format(self.__class__.__name__, self.id_num)

def __repr__(self):
return str(self)

def ToString(self):
return str(self)
65 changes: 63 additions & 2 deletions honeybee_energy_ph/properties/construction/opaque.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,71 @@

"""Passive House properties for honeybee_energy.construction.opaque.OpaqueConstruction Objects"""

try:
from typing import Any
except ImportError:
pass # Python 2.7


class OpaqueConstructionPhProperties_FromDictError(Exception):
def __init__(self, _expected_types, _input_type):
self.msg = 'Error: Expected type of "{}". Got: {}'.format(_expected_types, _input_type)
super(OpaqueConstructionPhProperties_FromDictError, self).__init__(self.msg)


class OpaqueConstructionPhProperties(object):
def __init__(self):
def __init__(self, _host=None):
# type (Any) -> None
self._host = _host
self.id_num = 0

def __repr__(self):
@property
def host(self):
return self._host

def duplicate(self, new_host=None):
# type: (Any) -> OpaqueConstructionPhProperties
return self.__copy__(new_host)

def __copy__(self, new_host=None):
# type: (Any) -> OpaqueConstructionPhProperties
host = new_host or self.host

new_obj = self.__class__(host)
new_obj.id_num = self.id_num
return new_obj

def to_dict(self, abridged=False):
# type: (bool) -> dict
d = {}

if abridged:
d["type"] = "OpaqueConstructionPhPropertiesAbridged"
else:
d["type"] = "OpaqueConstructionPhProperties"

d["id_num"] = self.id_num
return {"ph": d}

@classmethod
def from_dict(cls, _input_dict, host):
# type: (dict, Any) -> OpaqueConstructionPhProperties
valid_types = (
"OpaqueConstructionPhProperties",
"OpaqueConstructionPhPropertiesAbridged",
)
if _input_dict["type"] not in valid_types:
raise OpaqueConstructionPhProperties_FromDictError(valid_types, _input_dict["type"])

new_obj = cls(host)
new_obj.id_num = _input_dict["id_num"]
return new_obj

def __str__(self):
return "{}(id_num={!r})".format(self.__class__.__name__, self.id_num)

def __repr__(self):
return str(self)

def ToString(self):
return str(self)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest

from honeybee_energy_ph.properties.construction import air


def test_default_air_construction_properties_dict_round_trip():
s1 = air.AirBoundaryConstructionPhProperties("host")
d1 = s1.to_dict()
s2 = air.AirBoundaryConstructionPhProperties.from_dict(d1["ph"], None)

assert d1 == s2.to_dict()


def test_custom_air_construction_properties_dict_round_trip():
s1 = air.AirBoundaryConstructionPhProperties("host")
s1.id_num = 11223
d1 = s1.to_dict()
s2 = air.AirBoundaryConstructionPhProperties.from_dict(d1["ph"], None)

assert d1 == s2.to_dict()


def test_default_air_construction_properties_duplicate():
s1 = air.AirBoundaryConstructionPhProperties("host")
s2 = s1.duplicate()

assert s1.to_dict() == s2.to_dict()


def test_custom_air_construction_properties__wrong_type_from_dict():
wrong_dict = {
"type": "not_allowed_type",
}
with pytest.raises(air.AirBoundaryConstructionPhProperties_FromDictError):
s1 = air.AirBoundaryConstructionPhProperties.from_dict(wrong_dict, None)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest

from honeybee_energy_ph.properties.construction import opaque


def test_default_opaque_construction_properties_dict_round_trip():
s1 = opaque.OpaqueConstructionPhProperties("host")
d1 = s1.to_dict()
s2 = opaque.OpaqueConstructionPhProperties.from_dict(d1["ph"], None)

assert d1 == s2.to_dict()


def test_custom_opaque_construction_properties_dict_round_trip():
s1 = opaque.OpaqueConstructionPhProperties("host")
s1.id_num = 11223
d1 = s1.to_dict()
s2 = opaque.OpaqueConstructionPhProperties.from_dict(d1["ph"], None)

assert d1 == s2.to_dict()


def test_default_opaque_construction_properties_duplicate():
s1 = opaque.OpaqueConstructionPhProperties("host")
s2 = s1.duplicate()

assert s1.to_dict() == s2.to_dict()


def test_custom_opaque_construction_properties__wrong_type_from_dict():
wrong_dict = {
"type": "not_allowed_type",
}
with pytest.raises(opaque.OpaqueConstructionPhProperties_FromDictError):
s1 = opaque.OpaqueConstructionPhProperties.from_dict(wrong_dict, None)

0 comments on commit 232e964

Please sign in to comment.