Add support for translating state attributes (#77028)

* Allow defining state attributes in strings.json

* Add all climate attributes

* Remove support for custom device classes

* Address review comments
This commit is contained in:
Erik Montnemery 2022-12-09 08:22:29 +01:00 committed by GitHub
parent b172abaeeb
commit 8f761f44bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 190 additions and 0 deletions

View file

@ -25,5 +25,82 @@
"dry": "Dry",
"fan_only": "Fan only"
}
},
"state_attributes": {
"_": {
"aux_heat": { "name": "Aux heat" },
"current_humidity": { "name": "Current humidity" },
"current_temperature": { "name": "Current temperature" },
"fan_mode": {
"name": "Fan mode",
"state": {
"off": "[%key:common::state::off%]",
"on": "[%key:common::state::on%]",
"auto": "Auto",
"low": "Low",
"medium": "Medium",
"high": "High",
"top": "Top",
"middle": "Middle",
"focus": "Focus",
"diffuse": "Diffuse"
}
},
"fan_modes": {
"name": "Fan modes"
},
"humidity": { "name": "Target humidity" },
"hvac_action": {
"name": "Current action",
"state": {
"off": "Off",
"heating": "Heating",
"cooling": "Cooling",
"drying": "Drying",
"idle": "Idle",
"fan": "Fan"
}
},
"hvac_modes": {
"name": "HVAC modes"
},
"max_humidity": { "name": "Max target humidity" },
"max_temp": { "name": "Max target temperature" },
"min_humidity": { "name": "Min target humidity" },
"min_temp": { "name": "Min target temperature" },
"preset_mode": {
"name": "Preset",
"state": {
"none": "None",
"eco": "Eco",
"away": "Away",
"boost": "Boost",
"comfort": "Comfort",
"home": "Home",
"sleep": "Sleep",
"activity": "Activity"
}
},
"preset_modes": {
"name": "Presets"
},
"swing_mode": {
"name": "Swing mode",
"state": {
"off": "[%key:common::state::off%]",
"on": "[%key:common::state::on%]",
"both": "Both",
"vertical": "Vertical",
"horizontal": "Horizontal"
}
},
"swing_modes": {
"name": "Swing modes"
},
"target_temp_high": { "name": "Upper target temperature" },
"target_temp_low": { "name": "Lower target temperature" },
"target_temp_step": { "name": "Target temperature step" },
"temperature": { "name": "Target temperature" }
}
}
}

View file

@ -25,5 +25,106 @@
"off": "Off"
}
},
"state_attributes": {
"_": {
"aux_heat": {
"name": "Aux heat"
},
"current_humidity": {
"name": "Current humidity"
},
"current_temperature": {
"name": "Current temperature"
},
"fan_mode": {
"name": "Fan mode",
"state": {
"auto": "Auto",
"diffuse": "Diffuse",
"focus": "Focus",
"high": "High",
"low": "Low",
"medium": "Medium",
"middle": "Middle",
"off": "Off",
"on": "On",
"top": "Top"
}
},
"fan_modes": {
"name": "Fan modes"
},
"humidity": {
"name": "Target humidity"
},
"hvac_action": {
"name": "Current action",
"state": {
"cooling": "Cooling",
"drying": "Drying",
"fan": "Fan",
"heating": "Heating",
"idle": "Idle",
"off": "Off"
}
},
"hvac_modes": {
"name": "HVAC modes"
},
"max_humidity": {
"name": "Max target humidity"
},
"max_temp": {
"name": "Max target temperature"
},
"min_humidity": {
"name": "Min target humidity"
},
"min_temp": {
"name": "Min target temperature"
},
"preset_mode": {
"name": "Preset",
"state": {
"activity": "Activity",
"away": "Away",
"boost": "Boost",
"comfort": "Comfort",
"eco": "Eco",
"home": "Home",
"none": "None",
"sleep": "Sleep"
}
},
"preset_modes": {
"name": "Presets"
},
"swing_mode": {
"name": "Swing mode",
"state": {
"both": "Both",
"horizontal": "Horizontal",
"off": "Off",
"on": "On",
"vertical": "Vertical"
}
},
"swing_modes": {
"name": "Swing modes"
},
"target_temp_high": {
"name": "Upper target temperature"
},
"target_temp_low": {
"name": "Lower target temperature"
},
"target_temp_step": {
"name": "Target temperature step"
},
"temperature": {
"name": "Target temperature"
}
}
},
"title": "Climate"
}

View file

@ -224,6 +224,18 @@ def gen_strings_schema(config: Config, integration: Integration) -> vol.Schema:
cv.schema_with_slug_keys(str, slug_validator=lowercase_validator),
slug_validator=vol.Any("_", cv.slug),
),
vol.Optional("state_attributes"): cv.schema_with_slug_keys(
cv.schema_with_slug_keys(
{
vol.Optional("name"): str,
vol.Optional("state"): cv.schema_with_slug_keys(
str, slug_validator=lowercase_validator
),
},
slug_validator=lowercase_validator,
),
slug_validator=vol.Any("_", cv.slug),
),
vol.Optional("system_health"): {
vol.Optional("info"): {str: cv.string_with_no_html}
},