diff --git a/homeassistant/components/tuya/climate.py b/homeassistant/components/tuya/climate.py index 5b9ae4f5213..30f2238628b 100644 --- a/homeassistant/components/tuya/climate.py +++ b/homeassistant/components/tuya/climate.py @@ -208,6 +208,18 @@ def _get_temperature_wrappers( device, DPCode.TEMP_SET_F, prefer_function=True ) + # If there is a temp unit convert dpcode, override empty units + if ( + temp_unit_convert := DPCodeEnumWrapper.find_dpcode( + device, DPCode.TEMP_UNIT_CONVERT + ) + ) is not None: + for wrapper in (temp_current, temp_current_f, temp_set, temp_set_f): + if wrapper is not None and not wrapper.type_information.unit: + wrapper.type_information.unit = temp_unit_convert.read_device_status( + device + ) + # Get wrappers for celsius and fahrenheit # We need to check the unit of measurement current_celsius = _get_temperature_wrapper( diff --git a/tests/components/tuya/conftest.py b/tests/components/tuya/conftest.py index 41eb6abbc49..30a76ba3809 100644 --- a/tests/components/tuya/conftest.py +++ b/tests/components/tuya/conftest.py @@ -182,7 +182,11 @@ async def _create_device(hass: HomeAssistant, mock_device_code: str) -> Customer key: DeviceFunction( code=key, type=value["type"], - values=json_dumps(value["value"]), + values=( + values + if isinstance(values := value["value"], str) + else json_dumps(values) + ), ) for key, value in details["function"].items() } @@ -190,7 +194,11 @@ async def _create_device(hass: HomeAssistant, mock_device_code: str) -> Customer key: DeviceStatusRange( code=key, type=value["type"], - values=json_dumps(value["value"]), + values=( + values + if isinstance(values := value["value"], str) + else json_dumps(values) + ), ) for key, value in details["status_range"].items() } diff --git a/tests/components/tuya/fixtures/wk_B0eP8qYAdpUo4yR9.json b/tests/components/tuya/fixtures/wk_B0eP8qYAdpUo4yR9.json new file mode 100644 index 00000000000..082dfb66d52 --- /dev/null +++ b/tests/components/tuya/fixtures/wk_B0eP8qYAdpUo4yR9.json @@ -0,0 +1,53 @@ +{ + "endpoint": "https://apigw.tuyaeu.com", + "mqtt_connected": true, + "disabled_by": null, + "disabled_polling": false, + "name": "ITC-308-WIFI Thermostat", + "category": "wk", + "product_id": "B0eP8qYAdpUo4yR9", + "product_name": "ITC-308-WIFI Thermostat", + "online": true, + "sub": false, + "time_zone": "+01:00", + "active_time": "2022-02-08T10:49:39+00:00", + "create_time": "2022-02-08T10:49:39+00:00", + "update_time": "2022-02-08T10:49:39+00:00", + "function": { + "temp_unit_convert": { + "type": "Enum", + "value": "{\"range\":[\"c\",\"f\"]}" + }, + "temp_set": { + "type": "Integer", + "value": "{\"unit\":\"\",\"min\":-400,\"max\":2120,\"scale\":1,\"step\":5}" + } + }, + "status_range": { + "temp_unit_convert": { + "type": "Enum", + "value": "{\"range\":[\"c\",\"f\"]}" + }, + "temp_current": { + "type": "Integer", + "value": "{\"unit\":\"\u2103\",\"min\":-500,\"max\":1200,\"scale\":1,\"step\":10}" + }, + "temp_set": { + "type": "Integer", + "value": "{\"unit\":\"\",\"min\":-400,\"max\":2120,\"scale\":1,\"step\":5}" + }, + "temp_current_f": { + "type": "Integer", + "value": "{\"unit\":\"\u2109\",\"min\":-500,\"max\":2480,\"scale\":1,\"step\":10}" + } + }, + "status": { + "temp_unit_convert": "c", + "temp_current": 340, + "temp_set": 350, + "temp_current_f": 932 + }, + "set_up": true, + "support_local": true, + "warnings": null +} diff --git a/tests/components/tuya/snapshots/test_climate.ambr b/tests/components/tuya/snapshots/test_climate.ambr index c620dfbdb27..542c0a5c8f5 100644 --- a/tests/components/tuya/snapshots/test_climate.ambr +++ b/tests/components/tuya/snapshots/test_climate.ambr @@ -654,6 +654,68 @@ 'state': 'off', }) # --- +# name: test_platform_setup_and_discovery[climate.itc_308_wifi_thermostat-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'hvac_modes': list([ + ]), + 'max_temp': 212.0, + 'min_temp': -40.0, + 'target_temp_step': 0.5, + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'climate', + 'entity_category': None, + 'entity_id': 'climate.itc_308_wifi_thermostat', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + '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': , + 'translation_key': None, + 'unique_id': 'tuya.9Ry4oUpdAYq8Pe0Bkw', + 'unit_of_measurement': None, + }) +# --- +# name: test_platform_setup_and_discovery[climate.itc_308_wifi_thermostat-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'current_temperature': 34.0, + 'friendly_name': 'ITC-308-WIFI Thermostat', + 'hvac_modes': list([ + ]), + 'max_temp': 212.0, + 'min_temp': -40.0, + 'supported_features': , + 'target_temp_step': 0.5, + 'temperature': 35.0, + }), + 'context': , + 'entity_id': 'climate.itc_308_wifi_thermostat', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'off', + }) +# --- # name: test_platform_setup_and_discovery[climate.kabinet-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ @@ -1450,6 +1512,15 @@ 'target_temp_step': 1.0, }) # --- +# name: test_us_customary_system[climate.itc_308_wifi_thermostat] + ReadOnlyDict({ + 'current_temperature': 93, + 'max_temp': 414, + 'min_temp': -40, + 'target_temp_step': 0.5, + 'temperature': 95, + }) +# --- # name: test_us_customary_system[climate.kabinet] ReadOnlyDict({ 'current_temperature': 67, diff --git a/tests/components/tuya/snapshots/test_init.ambr b/tests/components/tuya/snapshots/test_init.ambr index f8588f1e2ef..ff8e26e2fb3 100644 --- a/tests/components/tuya/snapshots/test_init.ambr +++ b/tests/components/tuya/snapshots/test_init.ambr @@ -1301,6 +1301,37 @@ 'via_device_id': None, }) # --- +# name: test_device_registry[9Ry4oUpdAYq8Pe0Bkw] + DeviceRegistryEntrySnapshot({ + 'area_id': None, + 'config_entries': , + 'config_entries_subentries': , + 'configuration_url': None, + 'connections': set({ + }), + 'disabled_by': None, + 'entry_type': None, + 'hw_version': None, + 'id': , + 'identifiers': set({ + tuple( + 'tuya', + '9Ry4oUpdAYq8Pe0Bkw', + ), + }), + 'labels': set({ + }), + 'manufacturer': 'Tuya', + 'model': 'ITC-308-WIFI Thermostat', + 'model_id': 'B0eP8qYAdpUo4yR9', + 'name': 'ITC-308-WIFI Thermostat', + 'name_by_user': None, + 'primary_config_entry': , + 'serial_number': None, + 'sw_version': None, + 'via_device_id': None, + }) +# --- # name: test_device_registry[9c1vlsxoscm] DeviceRegistryEntrySnapshot({ 'area_id': None,