Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions homeassistant/components/tuya/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 10 additions & 2 deletions tests/components/tuya/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,23 @@ 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()
}
device.status_range = {
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()
}
Expand Down
53 changes: 53 additions & 0 deletions tests/components/tuya/fixtures/wk_B0eP8qYAdpUo4yR9.json
Original file line number Diff line number Diff line change
@@ -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
}
71 changes: 71 additions & 0 deletions tests/components/tuya/snapshots/test_climate.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -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': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'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': <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': <ClimateEntityFeature: 1>,
'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': <ClimateEntityFeature: 1>,
'target_temp_step': 0.5,
'temperature': 35.0,
}),
'context': <ANY>,
'entity_id': 'climate.itc_308_wifi_thermostat',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_platform_setup_and_discovery[climate.kabinet-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
Expand Down Expand Up @@ -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,
Expand Down
Loading