Skip to content

Commit f787f94

Browse files
committed
feat: add some nicer repr functions to equipment classes
1 parent 58f684f commit f787f94

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

pyomnilogic_local/_base.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,19 @@ def update_telemetry(self, telemetry: Telemetry) -> None:
149149
self.telemetry = cast(TelemetryT, specific_telemetry)
150150
else:
151151
self.telemetry = cast(TelemetryT, None)
152+
153+
def __repr__(self) -> str:
154+
"""Return a string representation of the equipment for debugging.
155+
156+
Returns:
157+
A string showing the class name, system_id, name, and state (if available).
158+
"""
159+
class_name = self.__class__.__name__
160+
parts = [f"system_id={self.system_id!r}", f"name={self.name!r}"]
161+
162+
# Include state if the equipment has telemetry with a state attribute
163+
if hasattr(self, "telemetry") and self.telemetry is not None:
164+
if (state := getattr(self.telemetry, "state", None)) is not None:
165+
parts.append(f"state={state!r}")
166+
167+
return f"{class_name}({', '.join(parts)})"

pyomnilogic_local/bow.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,31 @@ class Bow(OmniEquipment[MSPBoW, TelemetryBoW]):
138138
def __init__(self, omni: "OmniLogic", mspconfig: MSPBoW, telemetry: Telemetry) -> None:
139139
super().__init__(omni, mspconfig, telemetry)
140140

141+
def __repr__(self) -> str:
142+
"""Return a string representation of the Bow for debugging.
143+
144+
Returns:
145+
A string showing the class name, system_id, name, type, and equipment counts.
146+
"""
147+
parts = [f"system_id={self.system_id!r}", f"name={self.name!r}", f"type={self.equip_type!r}"]
148+
149+
# Add equipment counts
150+
parts.append(f"filters={len(self.filters)}")
151+
parts.append(f"pumps={len(self.pumps)}")
152+
parts.append(f"lights={len(self.lights)}")
153+
parts.append(f"relays={len(self.relays)}")
154+
parts.append(f"sensors={len(self.sensors)}")
155+
156+
# Add heater and chlorinator status (present or not)
157+
if self.heater is not None:
158+
parts.append("heater=True")
159+
if self.chlorinator is not None:
160+
parts.append("chlorinator=True")
161+
if len(self.csads) > 0:
162+
parts.append(f"csads={len(self.csads)}")
163+
164+
return f"Bow({', '.join(parts)})"
165+
141166
@property
142167
def equip_type(self) -> BodyOfWaterType | str:
143168
"""The equipment type of the bow (POOL or SPA)."""

pyomnilogic_local/omnilogic.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,27 @@ def __init__(self, host: str, port: int = 10444) -> None:
4242
self._api = OmniLogicAPI(host, port)
4343
self._refresh_lock = asyncio.Lock()
4444

45+
def __repr__(self) -> str:
46+
"""Return a string representation of the OmniLogic instance for debugging.
47+
48+
Returns:
49+
A string showing host, port, and counts of various equipment types.
50+
"""
51+
# Only show equipment counts if backyard has been initialized
52+
if hasattr(self, "backyard"):
53+
bow_count = len(self.backyard.bow)
54+
light_count = len(self.all_lights)
55+
relay_count = len(self.all_relays)
56+
pump_count = len(self.all_pumps)
57+
filter_count = len(self.all_filters)
58+
59+
return (
60+
f"OmniLogic(host={self.host!r}, port={self.port}, "
61+
f"bows={bow_count}, lights={light_count}, relays={relay_count}, "
62+
f"pumps={pump_count}, filters={filter_count})"
63+
)
64+
return f"OmniLogic(host={self.host!r}, port={self.port}, not_initialized=True)"
65+
4566
async def refresh(
4667
self,
4768
*,

0 commit comments

Comments
 (0)