Skip to content

Commit f2160c5

Browse files
committed
Refactor enums to use UnknownEnumMixin for consistent handling and improve module imports
1 parent 0c8f666 commit f2160c5

4 files changed

Lines changed: 48 additions & 43 deletions

File tree

pyoverkiz/enums/__init__.py

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,42 @@
22

33
# flake8: noqa: F403
44

5-
from .command import *
6-
from .execution import *
7-
from .gateway import *
8-
from .general import *
9-
from .measured_value_type import *
10-
from .protocol import *
11-
from .server import *
12-
from .state import *
13-
from .ui import *
5+
from enum import Enum
6+
7+
from pyoverkiz.enums import command as _command
8+
from pyoverkiz.enums import execution as _execution
9+
from pyoverkiz.enums import gateway as _gateway
10+
from pyoverkiz.enums import general as _general
11+
from pyoverkiz.enums import measured_value_type as _measured_value_type
12+
from pyoverkiz.enums import protocol as _protocol
13+
from pyoverkiz.enums import server as _server
14+
from pyoverkiz.enums import state as _state
15+
from pyoverkiz.enums import ui as _ui
16+
from pyoverkiz.enums.command import *
17+
from pyoverkiz.enums.execution import *
18+
from pyoverkiz.enums.gateway import *
19+
from pyoverkiz.enums.general import *
20+
from pyoverkiz.enums.measured_value_type import *
21+
from pyoverkiz.enums.protocol import *
22+
from pyoverkiz.enums.server import *
23+
from pyoverkiz.enums.state import *
24+
from pyoverkiz.enums.ui import *
25+
26+
__all__ = sorted(
27+
{
28+
name
29+
for module in (
30+
_command,
31+
_execution,
32+
_gateway,
33+
_general,
34+
_measured_value_type,
35+
_protocol,
36+
_server,
37+
_state,
38+
_ui,
39+
)
40+
for name, obj in vars(module).items()
41+
if isinstance(obj, type) and issubclass(obj, Enum)
42+
}
43+
)

pyoverkiz/enums/gateway.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
"""Enums for gateway types and related helpers."""
22

3-
import logging
43
from enum import IntEnum, StrEnum, unique
54

6-
_LOGGER = logging.getLogger(__name__)
5+
from pyoverkiz.enums.base import UnknownEnumMixin
76

87

98
@unique
10-
class GatewayType(IntEnum):
9+
class GatewayType(UnknownEnumMixin, IntEnum):
1110
"""Enumeration of known gateway types returned by Overkiz."""
1211

1312
UNKNOWN = -1
@@ -63,11 +62,6 @@ class GatewayType(IntEnum):
6362
TAHOMA_SWITCH_CH = 126
6463
TAHOMA_SWITCH_SC = 128
6564

66-
@classmethod
67-
def _missing_(cls, value): # type: ignore
68-
_LOGGER.warning(f"Unsupported value {value} has been returned for {cls}")
69-
return cls.UNKNOWN
70-
7165
@property
7266
def beautify_name(self) -> str:
7367
"""Return a human friendly name for the gateway type."""
@@ -78,7 +72,7 @@ def beautify_name(self) -> str:
7872

7973

8074
@unique
81-
class GatewaySubType(IntEnum):
75+
class GatewaySubType(UnknownEnumMixin, IntEnum):
8276
"""Sub-type enumeration for gateways to identify specific models/variants."""
8377

8478
UNKNOWN = -1
@@ -100,11 +94,6 @@ class GatewaySubType(IntEnum):
10094
TAHOMA_SECURITY_PRO = 16
10195
# TAHOMA_BOX_C_IO = 12 # Note: This is likely 17, but tahomalink.com lists it as 12
10296

103-
@classmethod
104-
def _missing_(cls, value): # type: ignore
105-
_LOGGER.warning(f"Unsupported value {value} has been returned for {cls}")
106-
return cls.UNKNOWN
107-
10897
@property
10998
def beautify_name(self) -> str:
11099
"""Return a human friendly name for the gateway sub-type."""

pyoverkiz/enums/general.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
# ruff: noqa: S105
44
# Enum values contain "TOKEN" in API event names, not passwords
55

6-
import logging
76
from enum import IntEnum, StrEnum, unique
87

9-
_LOGGER = logging.getLogger(__name__)
8+
from pyoverkiz.enums.base import UnknownEnumMixin
109

1110

1211
@unique
@@ -40,7 +39,7 @@ class DataType(IntEnum):
4039

4140

4241
@unique
43-
class FailureType(IntEnum):
42+
class FailureType(UnknownEnumMixin, IntEnum):
4443
"""Failure type codes returned by the API."""
4544

4645
UNKNOWN = -1
@@ -248,14 +247,8 @@ class FailureType(IntEnum):
248247
TIME_OUT_ON_COMMAND_PROGRESS = 20003
249248
DEVICE_NO_ANSWER = 60004
250249

251-
@classmethod
252-
def _missing_(cls, value): # type: ignore
253-
_LOGGER.warning(f"Unsupported value {value} has been returned for {cls}")
254-
return cls.UNKNOWN
255-
256-
257250
@unique
258-
class EventName(StrEnum):
251+
class EventName(UnknownEnumMixin, StrEnum):
259252
"""Enumeration of event names emitted by Overkiz."""
260253

261254
UNKNOWN = "Unknown"

pyoverkiz/enums/ui.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
# ruff: noqa: S105
44
# Enum values contain "PASS" in API names (e.g. PassAPC), not passwords
55

6-
import logging
76
from enum import StrEnum, unique
87

9-
_LOGGER = logging.getLogger(__name__)
8+
from pyoverkiz.enums.base import UnknownEnumMixin
109

1110

1211
@unique
13-
class UIClass(StrEnum):
12+
class UIClass(UnknownEnumMixin, StrEnum):
1413
"""Enumeration of UI classes used to describe device categories and behaviors."""
1514

1615
# A list of all defined UI classes from /reference/ui/classes
@@ -84,14 +83,8 @@ class UIClass(StrEnum):
8483

8584
UNKNOWN = "unknown"
8685

87-
@classmethod
88-
def _missing_(cls, value): # type: ignore
89-
_LOGGER.warning(f"Unsupported value {value} has been returned for {cls}")
90-
return cls.UNKNOWN
91-
92-
9386
@unique
94-
class UIWidget(StrEnum):
87+
class UIWidget(UnknownEnumMixin, StrEnum):
9588
"""Enumeration of UI widgets used by Overkiz for device presentation."""
9689

9790
# A list of all defined UI widgets from /reference/ui/widgets

0 commit comments

Comments
 (0)