Fix Tuya fan speeds with numeric values

This commit is contained in:
epenet
2025-08-04 13:25:56 +00:00
parent b76f47cd9f
commit 4616b76d6c
6 changed files with 351 additions and 1 deletions

View File

@@ -269,7 +269,9 @@ class TuyaFanEntity(TuyaEntity, FanEntity):
if self._speeds is not None: if self._speeds is not None:
if (value := self.device.status.get(self._speeds.dpcode)) is None: if (value := self.device.status.get(self._speeds.dpcode)) is None:
return None return None
return ordered_list_item_to_percentage(self._speeds.range, value) # range is always a list of strings, but value can be an integer
# so we need to convert it to a string - see #141231
return ordered_list_item_to_percentage(self._speeds.range, str(value))
return None return None

View File

@@ -214,6 +214,12 @@ DEVICE_MOCKS = {
# https://github.com/home-assistant/core/issues/143499 # https://github.com/home-assistant/core/issues/143499
Platform.SENSOR, Platform.SENSOR,
], ],
"fs_g0ewlb1vmwqljzji": [
# https://github.com/home-assistant/core/issues/141231
Platform.FAN,
Platform.LIGHT,
Platform.SELECT,
],
"gyd_lgekqfxdabipm3tn": [ "gyd_lgekqfxdabipm3tn": [
# https://github.com/home-assistant/core/issues/133173 # https://github.com/home-assistant/core/issues/133173
Platform.LIGHT, Platform.LIGHT,

View File

@@ -0,0 +1,134 @@
{
"endpoint": "https://apigw.tuyaeu.com",
"terminal_id": "REDACTED",
"mqtt_connected": true,
"disabled_by": null,
"disabled_polling": false,
"id": "XXX",
"name": "Ceiling Fan With Light",
"category": "fs",
"product_id": "g0ewlb1vmwqljzji",
"product_name": "Ceiling Fan With Light",
"online": true,
"sub": false,
"time_zone": "+01:00",
"active_time": "2025-03-22T22:57:04+00:00",
"create_time": "2025-03-22T22:57:04+00:00",
"update_time": "2025-03-22T22:57:04+00:00",
"function": {
"switch": {
"type": "Boolean",
"value": {}
},
"mode": {
"type": "Enum",
"value": {
"range": ["normal", "sleep", "nature"]
}
},
"fan_speed": {
"type": "Enum",
"value": {
"range": ["1", "2", "3", "4", "5", "6"]
}
},
"fan_direction": {
"type": "Enum",
"value": {
"range": ["forward", "reverse"]
}
},
"light": {
"type": "Boolean",
"value": {}
},
"bright_value": {
"type": "Integer",
"value": {
"min": 0,
"max": 100,
"scale": 0,
"step": 1
}
},
"temp_value": {
"type": "Integer",
"value": {
"min": 0,
"max": 100,
"scale": 0,
"step": 1
}
},
"countdown_set": {
"type": "Enum",
"value": {
"range": ["cancel", "1h", "2h", "4h", "8h"]
}
}
},
"status_range": {
"switch": {
"type": "Boolean",
"value": {}
},
"mode": {
"type": "Enum",
"value": {
"range": ["normal", "sleep", "nature"]
}
},
"fan_speed": {
"type": "Enum",
"value": {
"range": ["1", "2", "3", "4", "5", "6"]
}
},
"fan_direction": {
"type": "Enum",
"value": {
"range": ["forward", "reverse"]
}
},
"light": {
"type": "Boolean",
"value": {}
},
"bright_value": {
"type": "Integer",
"value": {
"min": 0,
"max": 100,
"scale": 0,
"step": 1
}
},
"temp_value": {
"type": "Integer",
"value": {
"min": 0,
"max": 100,
"scale": 0,
"step": 1
}
},
"countdown_set": {
"type": "Enum",
"value": {
"range": ["cancel", "1h", "2h", "4h", "8h"]
}
}
},
"status": {
"switch": true,
"mode": "normal",
"fan_speed": 1,
"fan_direction": "reverse",
"light": true,
"bright_value": 100,
"temp_value": 0,
"countdown_set": "off"
},
"set_up": true,
"support_local": true
}

View File

@@ -153,6 +153,70 @@
'state': 'on', 'state': 'on',
}) })
# --- # ---
# name: test_platform_setup_and_discovery[fs_g0ewlb1vmwqljzji][fan.ceiling_fan_with_light-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'preset_modes': list([
'normal',
'sleep',
'nature',
]),
}),
'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.ceiling_fan_with_light',
'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: 61>,
'translation_key': None,
'unique_id': 'tuya.XXX',
'unit_of_measurement': None,
})
# ---
# name: test_platform_setup_and_discovery[fs_g0ewlb1vmwqljzji][fan.ceiling_fan_with_light-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'direction': 'reverse',
'friendly_name': 'Ceiling Fan With Light',
'percentage': 16,
'percentage_step': 16.666666666666668,
'preset_mode': 'normal',
'preset_modes': list([
'normal',
'sleep',
'nature',
]),
'supported_features': <FanEntityFeature: 61>,
}),
'context': <ANY>,
'entity_id': 'fan.ceiling_fan_with_light',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---
# name: test_platform_setup_and_discovery[kj_yrzylxax1qspdgpp][fan.bree-entry] # name: test_platform_setup_and_discovery[kj_yrzylxax1qspdgpp][fan.bree-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({

View File

@@ -2022,6 +2022,87 @@
'state': 'off', 'state': 'off',
}) })
# --- # ---
# name: test_platform_setup_and_discovery[fs_g0ewlb1vmwqljzji][light.ceiling_fan_with_light-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'max_color_temp_kelvin': 6500,
'max_mireds': 500,
'min_color_temp_kelvin': 2000,
'min_mireds': 153,
'supported_color_modes': list([
<ColorMode.COLOR_TEMP: 'color_temp'>,
]),
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'light',
'entity_category': None,
'entity_id': 'light.ceiling_fan_with_light',
'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': 0,
'translation_key': None,
'unique_id': 'tuya.XXXlight',
'unit_of_measurement': None,
})
# ---
# name: test_platform_setup_and_discovery[fs_g0ewlb1vmwqljzji][light.ceiling_fan_with_light-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'brightness': 255,
'color_mode': <ColorMode.COLOR_TEMP: 'color_temp'>,
'color_temp': 500,
'color_temp_kelvin': 2000,
'friendly_name': 'Ceiling Fan With Light',
'hs_color': tuple(
30.601,
94.547,
),
'max_color_temp_kelvin': 6500,
'max_mireds': 500,
'min_color_temp_kelvin': 2000,
'min_mireds': 153,
'rgb_color': tuple(
255,
137,
14,
),
'supported_color_modes': list([
<ColorMode.COLOR_TEMP: 'color_temp'>,
]),
'supported_features': <LightEntityFeature: 0>,
'xy_color': tuple(
0.598,
0.383,
),
}),
'context': <ANY>,
'entity_id': 'light.ceiling_fan_with_light',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# ---
# name: test_platform_setup_and_discovery[gyd_lgekqfxdabipm3tn][light.colorful_pir_night_light-entry] # name: test_platform_setup_and_discovery[gyd_lgekqfxdabipm3tn][light.colorful_pir_night_light-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({

View File

@@ -414,6 +414,69 @@
'state': 'unavailable', 'state': 'unavailable',
}) })
# --- # ---
# name: test_platform_setup_and_discovery[fs_g0ewlb1vmwqljzji][select.ceiling_fan_with_light_countdown-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'options': list([
'cancel',
'1h',
'2h',
'4h',
'8h',
]),
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'select',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'select.ceiling_fan_with_light_countdown',
'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': 'Countdown',
'platform': 'tuya',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'countdown',
'unique_id': 'tuya.XXXcountdown_set',
'unit_of_measurement': None,
})
# ---
# name: test_platform_setup_and_discovery[fs_g0ewlb1vmwqljzji][select.ceiling_fan_with_light_countdown-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Ceiling Fan With Light Countdown',
'options': list([
'cancel',
'1h',
'2h',
'4h',
'8h',
]),
}),
'context': <ANY>,
'entity_id': 'select.ceiling_fan_with_light_countdown',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
})
# ---
# name: test_platform_setup_and_discovery[kj_yrzylxax1qspdgpp][select.bree_countdown-entry] # name: test_platform_setup_and_discovery[kj_yrzylxax1qspdgpp][select.bree_countdown-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({