Skip to content

Commit

Permalink
fix(hot_water): Add 'temp' attribute to hot-water recirc
Browse files Browse the repository at this point in the history
- Adds new 'water_temp' attribute for all piping
- Refactors hot-water
- Add __eq__ to _Base for testing
- Add tests
  • Loading branch information
ed-p-may committed Jun 8, 2023
1 parent 27906bc commit e03ffe6
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 7 deletions.
9 changes: 9 additions & 0 deletions honeybee_energy_ph/hvac/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,12 @@ def duplicate(self):
obj.user_data = copy(self.user_data)

return obj

def __eq__(self, other):
# type: (_PhHVACBase) -> bool
for k, v in self.__dict__.items():
if v != getattr(other, k):
if str(v) != str(getattr(other, k)): # Handle UUID Identifier
return False
return True

22 changes: 19 additions & 3 deletions honeybee_energy_ph/hvac/hot_water.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ def __init__(self,
_insul_conductivity=0.04,
_insul_refl=True,
_insul_quality=None,
_daily_period=24.0):
# type: (LineSegment3D, float, float, float, bool, None, float) -> None
_daily_period=24,
_water_temp=60.0,
*args, **kwargs):
# type: (LineSegment3D, float, float, float, bool, None, float, float, *Any, **Any) -> None
super(PhPipeSegment, self).__init__()
self.geometry = _geom
self.diameter_m = _diameter_m
Expand All @@ -46,6 +48,7 @@ def __init__(self,
self.insulation_reflective = _insul_refl
self.insulation_quality = _insul_quality
self.daily_period = _daily_period
self.water_temp = _water_temp

@property
def length_m(self):
Expand All @@ -62,6 +65,7 @@ def __copy__(self):
new_obj.insulation_reflective = self.insulation_reflective
new_obj.insulation_quality = self.insulation_quality
new_obj.daily_period = self.daily_period
new_obj.water_temp = self.water_temp
new_obj.identifier = self.identifier
new_obj.display_name = self.display_name
new_obj.user_data = copy(self.user_data)
Expand All @@ -82,6 +86,7 @@ def to_dict(self):
d['insulation_reflective'] = self.insulation_reflective
d['insulation_quality'] = self.insulation_quality
d['daily_period'] = self.daily_period
d['water_temp'] = self.water_temp
return d

@classmethod
Expand All @@ -96,6 +101,7 @@ def from_dict(cls, _input_dict):
new_obj.insulation_reflective = _input_dict['insulation_reflective']
new_obj.insulation_quality = _input_dict['insulation_quality']
new_obj.daily_period = _input_dict['daily_period']
new_obj.water_temp = _input_dict['water_temp']
new_obj.identifier = _input_dict['identifier']
new_obj.display_name = _input_dict['display_name']
new_obj.user_data = _input_dict['user_data']
Expand Down Expand Up @@ -129,6 +135,16 @@ def length_m(self):
# type: () -> float
return sum(s.length_m for s in self.segments)

@property
def water_temp(self):
# Return the length-weighted average water temperature of all the pipe segments
return sum(s.length_m * s.water_temp for s in self.segments) / self.length_m

@property
def daily_period(self):
# Return the length-weighted average daily period of all the pipe segments
return sum(s.length_m * s.daily_period for s in self.segments) / self.length_m

def add_segment(self, _segment):
# type: (PhPipeSegment) -> None
self._segments[_segment.identifier] = _segment
Expand Down Expand Up @@ -295,7 +311,7 @@ def __repr__(self):
def ToString(self):
return self.__repr__()


# -- Heaters ------------------------------------------------------------------


Expand Down
17 changes: 13 additions & 4 deletions honeybee_energy_ph/properties/hot_water/hw_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@ def __init__(self, _host):
self._host = _host
self.id_num = 0

self.tank_1 = None # Optional[PhSHWTank]
self.tank_2 = None # Optional[PhSHWTank]
self.tank_buffer = None # Optional[PhSHWTank]
self.tank_solar = None # Optional[PhSHWTank]
self.tank_1 = None # Optional[hot_water.PhSHWTank]
self.tank_2 = None # Optional[hot_water.PhSHWTank]
self.tank_buffer = None # Optional[hot_water.PhSHWTank]
self.tank_solar = None # Optional[hot_water.PhSHWTank]

self._heaters = {} # type: Dict[str, hot_water.PhHotWaterHeater]
self._branch_piping = {} # type: Dict[str, hot_water.PhPipeElement]
self._recirc_piping = {} # type: Dict[str, hot_water.PhPipeElement]

self._number_tap_points = None # type: Optional[int]

self.recirc_temp = 60.0 # type: float
self.recirc_hours = 24 # type: int

@property
def number_tap_points(self):
# type: () -> int
Expand Down Expand Up @@ -137,6 +140,8 @@ def to_dict(self, abridged=False):
d['recirc_piping'][recirc_piping.identifier] = recirc_piping.to_dict()

d['number_tap_points'] = self._number_tap_points
d['recirc_temp'] = self.recirc_temp
d['recirc_hours'] = self.recirc_hours

return {'ph': d}

Expand Down Expand Up @@ -176,6 +181,8 @@ def from_dict(cls, _input_dict, _host):
hot_water.PhPipeElement.from_dict(recirc_piping_dict))

new_prop._number_tap_points = _input_dict['number_tap_points']
new_prop.recirc_temp = _input_dict['recirc_temp']
new_prop.recirc_hours = _input_dict['recirc_hours']

return new_prop

Expand Down Expand Up @@ -207,6 +214,8 @@ def __copy__(self, new_host=None):
new_obj._recirc_piping[k] = v.duplicate()

new_obj._number_tap_points = self._number_tap_points
new_obj.recirc_temp = self.recirc_temp
new_obj.recirc_hours = self.recirc_hours

return new_obj

Expand Down
24 changes: 24 additions & 0 deletions tests/test_honeybee_energy_ph/test_hvac/test_hot_water_tank.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from honeybee_energy_ph.hvac.hot_water import PhSHWTank

def test_dict_roundtrip_PhSHWTank():
s1 = PhSHWTank()
d = s1.to_dict()

s2 = PhSHWTank.from_dict(d)
assert s2.to_dict() == d

# -- add user data
s2.user_data["test_key"] = "test_value"
assert "test_key" in s2.user_data
assert "test_key" not in s1.user_data
assert s1.to_dict() != s2.to_dict()

def test_duplicate_PhSHWTank():
t1 = PhSHWTank()
t2 = t1.duplicate()
assert t1 == t2
assert t1.to_dict() == t2.to_dict()
assert t1 is not t2
assert t1.user_data is not t2.user_data
assert t1.user_data == t2.user_data

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from honeybee_energy_ph.properties.hot_water.hw_system import SHWSystemPhProperties
from honeybee_energy_ph.hvac.hot_water import PhSHWTank, PhPipeElement

def test_basic_SHWSystemPhProperties_round_trip():
obj = SHWSystemPhProperties(None)
d = obj.to_dict()
new_obj = SHWSystemPhProperties.from_dict(d['ph'], None)
assert new_obj.to_dict() == d


def test_SHWSystemPhProperties_copy():
system = SHWSystemPhProperties(None)
system.id_num = 1
system.tank_1 = PhSHWTank()
system.tank_2 = PhSHWTank()
system.tank_buffer = PhSHWTank()
system.tank_solar = PhSHWTank()
system._heaters = {'heater_1': 1, 'heater_2': 2}
system._branch_piping = {'branch_1': PhPipeElement(), 'branch_2': PhPipeElement()}
system._recirc_piping = {'recirc_1': PhPipeElement(), 'recirc_2': PhPipeElement()}
system._number_tap_points = 2
system.recirc_temp = 50
system.recirc_hours = 2

new_system = system.__copy__()

assert new_system.id_num == system.id_num
assert new_system.tank_1 == system.tank_1
assert new_system.tank_2 == system.tank_2
assert new_system.tank_buffer == system.tank_buffer
assert new_system.tank_solar == system.tank_solar
assert new_system._heaters == system._heaters
assert new_system._branch_piping == system._branch_piping
assert new_system._recirc_piping == system._recirc_piping
assert new_system._number_tap_points == system._number_tap_points
assert new_system.recirc_temp == system.recirc_temp
assert new_system.recirc_hours == system.recirc_hours

0 comments on commit e03ffe6

Please sign in to comment.