Add quirk

This commit is contained in:
epenet
2025-11-03 08:29:39 +00:00
parent 546f089eae
commit 4abb397fd3
2 changed files with 23 additions and 5 deletions
+21 -2
View File
@@ -2,7 +2,7 @@
from __future__ import annotations
from dataclasses import dataclass
from dataclasses import dataclass, replace
from typing import TYPE_CHECKING, Any
from tuya_sharing import CustomerDevice, Manager
@@ -142,6 +142,25 @@ COVERS: dict[DeviceCategory, tuple[TuyaCoverEntityDescription, ...]] = {
),
}
_QUIRKS: dict[str, dict[str, Any]] = {
"cl_lfkr93x0ukp5gaia_control": {
# This model has percent_control / percent_state / situation_set
# but they never change - use control instead
"current_state": DPCode.CONTROL,
"current_position": None,
"set_position": None,
}
}
def _apply_quirk(
device: CustomerDevice, description: TuyaCoverEntityDescription
) -> TuyaCoverEntityDescription:
"""Apply quirk for specific device."""
if quirk := _QUIRKS.get(f"{device.category}_{device.product_id}_{description.key}"):
return replace(description, **quirk)
return description
async def async_setup_entry(
hass: HomeAssistant,
@@ -159,7 +178,7 @@ async def async_setup_entry(
device = manager.device_map[device_id]
if descriptions := COVERS.get(device.category):
entities.extend(
TuyaCoverEntity(device, manager, description)
TuyaCoverEntity(device, manager, _apply_quirk(device, description))
for description in descriptions
if (
description.key in device.function
@@ -535,7 +535,7 @@
'platform': 'tuya',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': <CoverEntityFeature: 15>,
'supported_features': <CoverEntityFeature: 11>,
'translation_key': 'curtain',
'unique_id': 'tuya.aiag5pku0x39rkfllccontrol',
'unit_of_measurement': None,
@@ -544,10 +544,9 @@
# name: test_platform_setup_and_discovery[cover.projector_screen_curtain-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'current_position': 100,
'device_class': 'curtain',
'friendly_name': 'Projector Screen Curtain',
'supported_features': <CoverEntityFeature: 15>,
'supported_features': <CoverEntityFeature: 11>,
}),
'context': <ANY>,
'entity_id': 'cover.projector_screen_curtain',