Add support for Tuya ks category (tower fan) (#148811)

This commit is contained in:
epenet 2025-07-16 09:24:20 +02:00 committed by GitHub
parent 9db5b0b3b7
commit d8de6e34dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 316 additions and 5 deletions

View File

@ -26,11 +26,23 @@ from .entity import TuyaEntity
from .models import EnumTypeData, IntegerTypeData
TUYA_SUPPORT_TYPE = {
"cs", # Dehumidifier
"fs", # Fan
"fsd", # Fan with Light
"fskg", # Fan wall switch
"kj", # Air Purifier
# Dehumidifier
# https://developer.tuya.com/en/docs/iot/categorycs?id=Kaiuz1vcz4dha
"cs",
# Fan
# https://developer.tuya.com/en/docs/iot/categoryfs?id=Kaiuz1xweel1c
"fs",
# Ceiling Fan Light
# https://developer.tuya.com/en/docs/iot/fsd?id=Kaof8eiei4c2v
"fsd",
# Fan wall switch
"fskg",
# Air Purifier
# https://developer.tuya.com/en/docs/iot/f?id=K9gf46h2s6dzm
"kj",
# Undocumented tower fan
# https://github.com/orgs/home-assistant/discussions/329
"ks",
}

View File

@ -242,6 +242,15 @@ LIGHTS: dict[str, tuple[TuyaLightEntityDescription, ...]] = {
entity_category=EntityCategory.CONFIG,
),
),
# Undocumented tower fan
# https://github.com/orgs/home-assistant/discussions/329
"ks": (
TuyaLightEntityDescription(
key=DPCode.LIGHT,
translation_key="backlight",
entity_category=EntityCategory.CONFIG,
),
),
# Unknown light product
# Found as VECINO RGBW as provided by diagnostics
# Not documented

View File

@ -431,6 +431,14 @@ SWITCHES: dict[str, tuple[SwitchEntityDescription, ...]] = {
entity_category=EntityCategory.CONFIG,
),
),
# Undocumented tower fan
# https://github.com/orgs/home-assistant/discussions/329
"ks": (
SwitchEntityDescription(
key=DPCode.ANION,
translation_key="ionizer",
),
),
# Alarm Host
# https://developer.tuya.com/en/docs/iot/alarm-hosts?id=K9gf48r87hyjk
"mal": (

View File

@ -79,6 +79,12 @@ DEVICE_MOCKS = {
Platform.SELECT,
Platform.SWITCH,
],
"ks_tower_fan": [
# https://github.com/orgs/home-assistant/discussions/329
Platform.FAN,
Platform.LIGHT,
Platform.SWITCH,
],
"mal_alarm_host": [
# Alarm Host support
Platform.ALARM_CONTROL_PANEL,

View File

@ -0,0 +1,107 @@
{
"endpoint": "https://apigw.tuyaeu.com",
"terminal_id": "mock_terminal_id",
"mqtt_connected": true,
"disabled_by": null,
"disabled_polling": false,
"id": "mock_device_id",
"name": "Tower Fan CA-407G Smart",
"category": "ks",
"product_id": "j9fa8ahzac8uvlfl",
"product_name": "Tower Fan CA-407G Smart",
"online": true,
"sub": false,
"time_zone": "+02:00",
"active_time": "2025-07-14T11:22:54+00:00",
"create_time": "2025-07-14T11:22:54+00:00",
"update_time": "2025-07-14T11:22:54+00:00",
"function": {
"switch": {
"type": "Boolean",
"value": {}
},
"fan_speed": {
"type": "Integer",
"value": {
"unit": "",
"min": 1,
"max": 12,
"scale": 0,
"step": 1
}
},
"mode": {
"type": "Enum",
"value": {
"range": ["ordinary", "nature", "sleep"]
}
},
"switch_horizontal": {
"type": "Boolean",
"value": {}
},
"anion": {
"type": "Boolean",
"value": {}
},
"light": {
"type": "Boolean",
"value": {}
}
},
"status_range": {
"switch": {
"type": "Boolean",
"value": {}
},
"fan_speed": {
"type": "Integer",
"value": {
"unit": "",
"min": 1,
"max": 12,
"scale": 0,
"step": 1
}
},
"mode": {
"type": "Enum",
"value": {
"range": ["ordinary", "nature", "sleep"]
}
},
"switch_horizontal": {
"type": "Boolean",
"value": {}
},
"anion": {
"type": "Boolean",
"value": {}
},
"light": {
"type": "Boolean",
"value": {}
},
"countdown_left": {
"type": "Integer",
"value": {
"unit": "min",
"min": 0,
"max": 721,
"scale": 0,
"step": 1
}
}
},
"status": {
"switch": false,
"fan_speed": 5,
"mode": "ordinary",
"switch_horizontal": true,
"anion": false,
"light": true,
"countdown_left": 0
},
"set_up": false,
"support_local": true
}

View File

@ -210,3 +210,67 @@
'state': 'off',
})
# ---
# name: test_platform_setup_and_discovery[ks_tower_fan][fan.tower_fan_ca_407g_smart-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'preset_modes': list([
'ordinary',
'nature',
'sleep',
]),
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'fan',
'entity_category': None,
'entity_id': 'fan.tower_fan_ca_407g_smart',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': None,
'platform': 'tuya',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': <FanEntityFeature: 59>,
'translation_key': None,
'unique_id': 'tuya.mock_device_id',
'unit_of_measurement': None,
})
# ---
# name: test_platform_setup_and_discovery[ks_tower_fan][fan.tower_fan_ca_407g_smart-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Tower Fan CA-407G Smart',
'oscillating': True,
'percentage': 37,
'percentage_step': 1.0,
'preset_mode': 'ordinary',
'preset_modes': list([
'ordinary',
'nature',
'sleep',
]),
'supported_features': <FanEntityFeature: 59>,
}),
'context': <ANY>,
'entity_id': 'fan.tower_fan_ca_407g_smart',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---

View File

@ -56,3 +56,60 @@
'state': 'on',
})
# ---
# name: test_platform_setup_and_discovery[ks_tower_fan][light.tower_fan_ca_407g_smart_backlight-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'supported_color_modes': list([
<ColorMode.ONOFF: 'onoff'>,
]),
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'light',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'light.tower_fan_ca_407g_smart_backlight',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Backlight',
'platform': 'tuya',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'backlight',
'unique_id': 'tuya.mock_device_idlight',
'unit_of_measurement': None,
})
# ---
# name: test_platform_setup_and_discovery[ks_tower_fan][light.tower_fan_ca_407g_smart_backlight-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'color_mode': <ColorMode.ONOFF: 'onoff'>,
'friendly_name': 'Tower Fan CA-407G Smart Backlight',
'supported_color_modes': list([
<ColorMode.ONOFF: 'onoff'>,
]),
'supported_features': <LightEntityFeature: 0>,
}),
'context': <ANY>,
'entity_id': 'light.tower_fan_ca_407g_smart_backlight',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---

View File

@ -677,6 +677,54 @@
'state': 'off',
})
# ---
# name: test_platform_setup_and_discovery[ks_tower_fan][switch.tower_fan_ca_407g_smart_ionizer-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'switch',
'entity_category': None,
'entity_id': 'switch.tower_fan_ca_407g_smart_ionizer',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Ionizer',
'platform': 'tuya',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'ionizer',
'unique_id': 'tuya.mock_device_idanion',
'unit_of_measurement': None,
})
# ---
# name: test_platform_setup_and_discovery[ks_tower_fan][switch.tower_fan_ca_407g_smart_ionizer-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Tower Fan CA-407G Smart Ionizer',
}),
'context': <ANY>,
'entity_id': 'switch.tower_fan_ca_407g_smart_ionizer',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_platform_setup_and_discovery[mal_alarm_host][switch.multifunction_alarm_arm_beep-entry]
EntityRegistryEntrySnapshot({
'aliases': set({