mirror of
https://github.com/home-assistant/core.git
synced 2026-09-27 01:46:11 -04:00
Move quirks to sub-folder
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from .device_quirk import DeviceQuirk, TuyaCoverDefinition, TuyaCoverDeviceClass
|
||||
from .device_quirk import TuyaCoverDefinition, TuyaCoverDeviceClass, TuyaDeviceQuirk
|
||||
from .homeassistant import parse_enum
|
||||
from .registry import QuirksRegistry
|
||||
|
||||
@@ -11,38 +11,8 @@ __all__ = [
|
||||
"QuirksRegistry",
|
||||
"TuyaCoverDefinition",
|
||||
"TuyaCoverDeviceClass",
|
||||
"TuyaDeviceQuirk",
|
||||
"parse_enum",
|
||||
]
|
||||
|
||||
TUYA_QUIRKS_REGISTRY = QuirksRegistry()
|
||||
|
||||
(
|
||||
# This model has percent_state and percent_control but percent_state never
|
||||
# gets updated - force percent_control instead
|
||||
DeviceQuirk()
|
||||
.applies_to(category="cl", product_id="g1cp07dsqnbdbbki")
|
||||
.add_cover(
|
||||
key="control",
|
||||
translation_key="curtain",
|
||||
translation_string="curtain",
|
||||
current_state_dp_code="control",
|
||||
current_position_dp_code="percent_control",
|
||||
set_position_dp_code="percent_control",
|
||||
device_class=TuyaCoverDeviceClass.CURTAIN,
|
||||
)
|
||||
.register(TUYA_QUIRKS_REGISTRY)
|
||||
)
|
||||
(
|
||||
# This model has percent_control / percent_state / situation_set
|
||||
# but they never get updated - use control instead to get the state
|
||||
DeviceQuirk()
|
||||
.applies_to(category="cl", product_id="lfkr93x0ukp5gaia")
|
||||
.add_cover(
|
||||
key="control",
|
||||
translation_key="curtain",
|
||||
translation_string="curtain",
|
||||
current_state_dp_code="control",
|
||||
device_class=TuyaCoverDeviceClass.CURTAIN,
|
||||
)
|
||||
.register(TUYA_QUIRKS_REGISTRY)
|
||||
)
|
||||
|
||||
@@ -32,7 +32,7 @@ class TuyaCoverDefinition(BaseTuyaDefinition):
|
||||
|
||||
|
||||
@dataclass
|
||||
class DeviceQuirk:
|
||||
class TuyaDeviceQuirk:
|
||||
"""Quirk for Tuya device."""
|
||||
|
||||
_applies_to: list[tuple[str, str]]
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
"""Quirks for Tuya."""
|
||||
@@ -0,0 +1,37 @@
|
||||
"""Quirks for Tuya."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from .. import TUYA_QUIRKS_REGISTRY
|
||||
from ..device_quirk import TuyaCoverDeviceClass, TuyaDeviceQuirk
|
||||
|
||||
(
|
||||
# This model has percent_state and percent_control but percent_state never
|
||||
# gets updated - force percent_control instead
|
||||
TuyaDeviceQuirk()
|
||||
.applies_to(category="cl", product_id="g1cp07dsqnbdbbki")
|
||||
.add_cover(
|
||||
key="control",
|
||||
translation_key="curtain",
|
||||
translation_string="curtain",
|
||||
current_state_dp_code="control",
|
||||
current_position_dp_code="percent_control",
|
||||
set_position_dp_code="percent_control",
|
||||
device_class=TuyaCoverDeviceClass.CURTAIN,
|
||||
)
|
||||
.register(TUYA_QUIRKS_REGISTRY)
|
||||
)
|
||||
(
|
||||
# This model has percent_control / percent_state / situation_set
|
||||
# but they never get updated - use control instead to get the state
|
||||
TuyaDeviceQuirk()
|
||||
.applies_to(category="cl", product_id="lfkr93x0ukp5gaia")
|
||||
.add_cover(
|
||||
key="control",
|
||||
translation_key="curtain",
|
||||
translation_string="curtain",
|
||||
current_state_dp_code="control",
|
||||
device_class=TuyaCoverDeviceClass.CURTAIN,
|
||||
)
|
||||
.register(TUYA_QUIRKS_REGISTRY)
|
||||
)
|
||||
@@ -7,7 +7,7 @@ from typing import TYPE_CHECKING, Self
|
||||
from tuya_sharing import CustomerDevice
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .device_quirk import DeviceQuirk
|
||||
from .device_quirk import TuyaDeviceQuirk
|
||||
|
||||
|
||||
class QuirksRegistry:
|
||||
@@ -15,7 +15,7 @@ class QuirksRegistry:
|
||||
|
||||
instance: Self
|
||||
|
||||
_quirks: dict[str, dict[str, DeviceQuirk]]
|
||||
_quirks: dict[str, dict[str, TuyaDeviceQuirk]]
|
||||
|
||||
def __new__(cls) -> Self:
|
||||
"""Create a new class."""
|
||||
@@ -27,10 +27,10 @@ class QuirksRegistry:
|
||||
"""Initialize the registry."""
|
||||
self._quirks = {}
|
||||
|
||||
def register(self, category: str, product_id: str, quirk: DeviceQuirk) -> None:
|
||||
def register(self, category: str, product_id: str, quirk: TuyaDeviceQuirk) -> None:
|
||||
"""Register a quirk for a specific device type."""
|
||||
self._quirks.setdefault(category, {})[product_id] = quirk
|
||||
|
||||
def get_quirk_for_device(self, device: CustomerDevice) -> DeviceQuirk | None:
|
||||
def get_quirk_for_device(self, device: CustomerDevice) -> TuyaDeviceQuirk | None:
|
||||
"""Get the quirk for a specific device."""
|
||||
return self._quirks.get(device.category, {}).get(device.product_id)
|
||||
|
||||
Reference in New Issue
Block a user