Skip to content

Commit f351efe

Browse files
authored
Add entity definition classes (#67)
* Add entity definition classes * Remove key * Add camera * Fix tests * Improve * Refactor * Reduce * Reduce * Reorder
1 parent 7d97bf3 commit f351efe

File tree

19 files changed

+214
-1
lines changed

19 files changed

+214
-1
lines changed

src/tuya_device_handlers/device_wrapper/alarm_control_panel.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,28 @@
33
from __future__ import annotations
44

55
import base64
6+
from dataclasses import dataclass
67
from typing import TYPE_CHECKING, Any
78

89
from ..helpers.homeassistant import (
910
TuyaAlarmControlPanelAction,
1011
TuyaAlarmControlPanelState,
1112
)
1213
from ..type_information import EnumTypeInformation
14+
from .base import DeviceWrapper
1315
from .common import DPCodeEnumWrapper, DPCodeRawWrapper
1416

1517
if TYPE_CHECKING:
1618
from tuya_sharing import CustomerDevice # type: ignore[import-untyped]
1719

1820

21+
@dataclass
22+
class TuyaAlarmControlPanelDefinition:
23+
action_wrapper: DeviceWrapper[TuyaAlarmControlPanelAction]
24+
changed_by_wrapper: DeviceWrapper[str] | None
25+
state_wrapper: DeviceWrapper[TuyaAlarmControlPanelState]
26+
27+
1928
class AlarmChangedByWrapper(DPCodeRawWrapper[str]):
2029
"""Wrapper for changed_by.
2130

src/tuya_device_handlers/device_wrapper/binary_sensor.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@
22

33
from __future__ import annotations
44

5+
from dataclasses import dataclass
56
from typing import TYPE_CHECKING, Self
67

78
from ..type_information import BitmapTypeInformation
9+
from .base import DeviceWrapper
810
from .common import DPCodeBitmapWrapper, DPCodeWrapper
911

1012
if TYPE_CHECKING:
1113
from tuya_sharing import CustomerDevice # type: ignore[import-untyped]
1214

1315

16+
@dataclass
17+
class TuyaBinarySensorDefinition:
18+
binary_sensor_wrapper: DeviceWrapper[bool]
19+
20+
1421
class DPCodeBitmapBitWrapper(DPCodeBitmapWrapper[bool]):
1522
"""Simple wrapper for a specific bit in bitmap values."""
1623

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""Tuya device wrapper."""
2+
3+
from dataclasses import dataclass
4+
5+
from ..device_wrapper import DeviceWrapper
6+
7+
8+
@dataclass
9+
class TuyaButtonDefinition:
10+
button_wrapper: DeviceWrapper[bool]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""Tuya device wrapper."""
2+
3+
from dataclasses import dataclass
4+
5+
from ..device_wrapper import DeviceWrapper
6+
7+
8+
@dataclass
9+
class TuyaCameraDefinition:
10+
motion_detection_switch: DeviceWrapper[bool] | None
11+
recording_status: DeviceWrapper[bool] | None

src/tuya_device_handlers/device_wrapper/climate.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@
66
from dataclasses import dataclass
77
from typing import TYPE_CHECKING, Any, Self
88

9-
from ..helpers.homeassistant import TuyaClimateHVACMode, TuyaClimateSwingMode
9+
from ..helpers.homeassistant import (
10+
TuyaClimateHVACMode,
11+
TuyaClimateSwingMode,
12+
TuyaUnitOfTemperature,
13+
)
1014
from ..type_information import EnumTypeInformation
1115
from .base import DeviceWrapper
1216
from .common import DPCodeBooleanWrapper, DPCodeEnumWrapper
1317

1418
if TYPE_CHECKING:
1519
from tuya_sharing import CustomerDevice # type: ignore[import-untyped]
1620

21+
1722
_DEFAULT_DEVICE_MODE_TO_HVACMODE = {
1823
"auto": TuyaClimateHVACMode.HEAT_COOL,
1924
"cold": TuyaClimateHVACMode.COOL,
@@ -27,6 +32,20 @@
2732
}
2833

2934

35+
@dataclass
36+
class TuyaClimateDefinition:
37+
current_humidity_wrapper: DeviceWrapper[int] | None
38+
current_temperature_wrapper: DeviceWrapper[float] | None
39+
fan_mode_wrapper: DeviceWrapper[str] | None
40+
hvac_mode_wrapper: DeviceWrapper[TuyaClimateHVACMode] | None
41+
preset_wrapper: DeviceWrapper[str] | None
42+
set_temperature_wrapper: DeviceWrapper[float] | None
43+
swing_wrapper: DeviceWrapper[TuyaClimateSwingMode] | None
44+
switch_wrapper: DeviceWrapper[bool] | None
45+
target_humidity_wrapper: DeviceWrapper[int] | None
46+
temperature_unit: TuyaUnitOfTemperature
47+
48+
3049
@dataclass(kw_only=True)
3150
class SwingModeCompositeWrapper(DeviceWrapper[TuyaClimateSwingMode]):
3251
"""Wrapper for managing swing mode across multiple boolean DPCodes.

src/tuya_device_handlers/device_wrapper/cover.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,28 @@
22

33
from __future__ import annotations
44

5+
from dataclasses import dataclass
56
from typing import TYPE_CHECKING
67

78
from ..helpers.homeassistant import TuyaCoverAction
89
from ..type_information import EnumTypeInformation
10+
from .base import DeviceWrapper
911
from .common import DPCodeBooleanWrapper, DPCodeEnumWrapper
1012
from .extended import DPCodePercentageWrapper
1113

1214
if TYPE_CHECKING:
1315
from tuya_sharing import CustomerDevice # type: ignore[import-untyped]
1416

1517

18+
@dataclass
19+
class TuyaCoverDefinition:
20+
current_position_wrapper: DeviceWrapper[int] | None
21+
current_state_wrapper: DeviceWrapper[bool] | None
22+
instruction_wrapper: DeviceWrapper[TuyaCoverAction] | None
23+
set_position_wrapper: DeviceWrapper[int] | None
24+
tilt_position_wrapper: DeviceWrapper[int] | None
25+
26+
1627
class ControlBackModePercentageMappingWrapper(DPCodePercentageWrapper):
1728
"""Wrapper for a cover with control_back_mode support.
1829

src/tuya_device_handlers/device_wrapper/event.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@
33
from __future__ import annotations
44

55
import base64
6+
from dataclasses import dataclass
67
from typing import TYPE_CHECKING, Any
78

9+
from .base import DeviceWrapper
810
from .common import DPCodeEnumWrapper, DPCodeRawWrapper, DPCodeStringWrapper
911

1012
if TYPE_CHECKING:
1113
from tuya_sharing import CustomerDevice # type: ignore[import-untyped]
1214

1315

16+
@dataclass
17+
class TuyaEventDefinition:
18+
event_wrapper: DeviceWrapper[tuple[str, dict[str, Any] | None]]
19+
20+
1421
class SimpleEventEnumWrapper(DPCodeEnumWrapper[tuple[str, None]]):
1522
"""Wrapper for event enum DP codes.
1623

src/tuya_device_handlers/device_wrapper/fan.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,28 @@
22

33
from __future__ import annotations
44

5+
from dataclasses import dataclass
56
from typing import TYPE_CHECKING, Any
67

78
from ..helpers.homeassistant import TuyaFanDirection
89
from ..type_information import EnumTypeInformation, IntegerTypeInformation
10+
from .base import DeviceWrapper
911
from .common import DPCodeEnumWrapper
1012
from .extended import DPCodeRemappedIntegerWrapper
1113

1214
if TYPE_CHECKING:
1315
from tuya_sharing import CustomerDevice # type: ignore[import-untyped]
1416

1517

18+
@dataclass
19+
class TuyaFanDefinition:
20+
direction_wrapper: DeviceWrapper[TuyaFanDirection] | None
21+
mode_wrapper: DeviceWrapper[str] | None
22+
oscillate_wrapper: DeviceWrapper[bool] | None
23+
speed_wrapper: DeviceWrapper[int] | None
24+
switch_wrapper: DeviceWrapper[bool] | None
25+
26+
1627
class FanDirectionEnumWrapper(DPCodeEnumWrapper[TuyaFanDirection]):
1728
"""Wrapper for fan direction DP code."""
1829

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Tuya device wrapper."""
2+
3+
from dataclasses import dataclass
4+
5+
from ..device_wrapper import DeviceWrapper
6+
7+
8+
@dataclass
9+
class TuyaHumidifierDefinition:
10+
current_humidity_wrapper: DeviceWrapper[int] | None = None
11+
mode_wrapper: DeviceWrapper[str] | None = None
12+
switch_wrapper: DeviceWrapper[bool] | None = None
13+
target_humidity_wrapper: DeviceWrapper[int] | None = None

src/tuya_device_handlers/device_wrapper/light.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,28 @@
22

33
from __future__ import annotations
44

5+
from dataclasses import dataclass
56
import json
67
from typing import TYPE_CHECKING, Any
78

89
from ..type_information import IntegerTypeInformation
910
from ..utils import RemapHelper
11+
from .base import DeviceWrapper
1012
from .common import DPCodeIntegerWrapper, DPCodeJsonWrapper
1113

1214
if TYPE_CHECKING:
1315
from tuya_sharing import CustomerDevice # type: ignore[import-untyped]
1416

1517

18+
@dataclass
19+
class TuyaLightDefinition:
20+
brightness_wrapper: DeviceWrapper[int] | None
21+
color_data_wrapper: DeviceWrapper[tuple[float, float, float]] | None
22+
color_mode_wrapper: DeviceWrapper[str] | None
23+
color_temp_wrapper: DeviceWrapper[int] | None
24+
switch_wrapper: DeviceWrapper[bool]
25+
26+
1627
class BrightnessWrapper(DPCodeIntegerWrapper[int]):
1728
"""Wrapper for brightness DP code.
1829

0 commit comments

Comments
 (0)