Skip to content

Commit bb37125

Browse files
committed
feat: add custom exception classes for better error handling
- Add OmniEquipmentNotReadyError for equipment in non-ready states - Add OmniEquipmentNotInitializedError for uninitialized equipment - Add OmniConnectionError for controller communication failures - Export all exceptions in __init__.py for easy importing - Replace ValueError with OmniEquipmentNotInitializedError in ColorLogicLight methods All exceptions inherit from OmniLogicLocalError base class and include comprehensive docstrings with usage examples.
1 parent 086426f commit bb37125

3 files changed

Lines changed: 48 additions & 4 deletions

File tree

pyomnilogic_local/__init__.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
from .omnilogic import OmniLogic
2+
from .util import (
3+
OmniConnectionError,
4+
OmniEquipmentNotInitializedError,
5+
OmniEquipmentNotReadyError,
6+
OmniLogicLocalError,
7+
)
28

3-
__all__ = ["OmniLogic"]
9+
__all__ = [
10+
"OmniLogic",
11+
"OmniLogicLocalError",
12+
"OmniEquipmentNotReadyError",
13+
"OmniEquipmentNotInitializedError",
14+
"OmniConnectionError",
15+
]

pyomnilogic_local/colorlogiclight.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
ColorLogicSpeed,
1212
LightShows,
1313
)
14+
from pyomnilogic_local.util import OmniEquipmentNotInitializedError
1415

1516
_LOGGER = logging.getLogger(__name__)
1617

@@ -70,13 +71,13 @@ def special_effect(self) -> int:
7071
async def turn_on(self) -> None:
7172
"""Turns the light on."""
7273
if self.bow_id is None or self.system_id is None:
73-
raise ValueError("Cannot turn on light: bow_id or system_id is None")
74+
raise OmniEquipmentNotInitializedError("Cannot turn on light: bow_id or system_id is None")
7475
await self._api.async_set_equipment(self.bow_id, self.system_id, True)
7576

7677
async def turn_off(self) -> None:
7778
"""Turns the light off."""
7879
if self.bow_id is None or self.system_id is None:
79-
raise ValueError("Cannot turn off light: bow_id or system_id is None")
80+
raise OmniEquipmentNotInitializedError("Cannot turn off light: bow_id or system_id is None")
8081
await self._api.async_set_equipment(self.bow_id, self.system_id, False)
8182

8283
async def set_show(
@@ -102,7 +103,7 @@ async def set_show(
102103
brightness = ColorLogicBrightness.ONE_HUNDRED_PERCENT
103104

104105
if self.bow_id is None or self.system_id is None:
105-
raise ValueError("Cannot set light show: bow_id or system_id is None")
106+
raise OmniEquipmentNotInitializedError("Cannot set light show: bow_id or system_id is None")
106107

107108
await self._api.async_set_light_show(
108109
self.bow_id,

pyomnilogic_local/util.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,37 @@ class OmniLogicLocalError(Exception):
1111
"""Base exception for python-omnilogic-local."""
1212

1313

14+
class OmniEquipmentNotReadyError(OmniLogicLocalError):
15+
"""Raised when equipment cannot accept commands due to its current state.
16+
17+
Examples:
18+
- Light in FIFTEEN_SECONDS_WHITE state
19+
- Light in CHANGING_SHOW state
20+
- Light in POWERING_OFF state
21+
- Light in COOLDOWN state
22+
- Equipment performing initialization or calibration
23+
"""
24+
25+
26+
class OmniEquipmentNotInitializedError(OmniLogicLocalError):
27+
"""Raised when equipment has not been properly initialized.
28+
29+
This typically occurs when required identifiers (bow_id or system_id) are None,
30+
indicating the equipment hasn't been populated from telemetry data yet.
31+
"""
32+
33+
34+
class OmniConnectionError(OmniLogicLocalError):
35+
"""Raised when communication with the OmniLogic controller fails.
36+
37+
Examples:
38+
- UDP socket timeout
39+
- Network unreachable
40+
- Invalid response from controller
41+
- Protocol errors
42+
"""
43+
44+
1445
class PrettyEnum(Enum):
1546
def pretty(self) -> str:
1647
return self.name.replace("_", " ").title()

0 commit comments

Comments
 (0)