Add support for translating custom attribute state (#83386)

* Add support for translating custom attribute state

* Address review comment

* Rename attribute to state_attributes, allow naming attributes
This commit is contained in:
Erik Montnemery 2022-12-21 10:43:49 +01:00 committed by GitHub
parent fc94569a0d
commit 255f35b979
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 83 additions and 6 deletions

View File

@ -104,6 +104,7 @@ class DemoClimate(ClimateEntity):
"""Representation of a demo climate device."""
_attr_should_poll = False
_attr_translation_key = "ubercool"
def __init__(
self,
@ -157,9 +158,9 @@ class DemoClimate(ClimateEntity):
self._hvac_mode = hvac_mode
self._aux = aux
self._current_swing_mode = swing_mode
self._fan_modes = ["On Low", "On High", "Auto Low", "Auto High", "Off"]
self._fan_modes = ["on_low", "on_high", "auto_low", "auto_high", "off"]
self._hvac_modes = hvac_modes
self._swing_modes = ["Auto", "1", "2", "3", "Off"]
self._swing_modes = ["auto", "1", "2", "3", "off"]
self._target_temperature_high = target_temp_high
self._target_temperature_low = target_temp_low

View File

@ -63,6 +63,29 @@
}
},
"entity": {
"climate": {
"ubercool": {
"state_attributes": {
"fan_mode": {
"state": {
"auto_high": "Auto High",
"auto_low": "Auto Low",
"on_high": "On High",
"on_low": "On Low"
}
},
"swing_mode": {
"state": {
"1": "1",
"2": "2",
"3": "3",
"auto": "Auto",
"off": "Off"
}
}
}
}
},
"select": {
"speed": {
"state": {
@ -81,6 +104,15 @@
"sleep": "Sleep"
}
}
},
"vacuum": {
"model_s": {
"state_attributes": {
"cleaned_area": {
"name": "Cleaned Area"
}
}
}
}
}
}

View File

@ -1,5 +1,28 @@
{
"entity": {
"climate": {
"ubercool": {
"state_attributes": {
"fan_mode": {
"state": {
"auto_high": "Auto High",
"auto_low": "Auto Low",
"on_high": "On High",
"on_low": "On Low"
}
},
"swing_mode": {
"state": {
"1": "1",
"2": "2",
"3": "3",
"auto": "Auto",
"off": "Off"
}
}
}
}
},
"select": {
"speed": {
"state": {
@ -18,6 +41,15 @@
"sleep": "Sleep"
}
}
},
"vacuum": {
"model_s": {
"state_attributes": {
"cleaned_area": {
"name": "Cleaned Area"
}
}
}
}
},
"issues": {
@ -36,7 +68,8 @@
"fix_flow": {
"abort": {
"not_tea_time": "Can not re-heat the tea at this time"
}
},
"step": {}
},
"title": "The tea is cold"
},
@ -62,6 +95,9 @@
},
"options": {
"step": {
"init": {
"data": {}
},
"options_1": {
"data": {
"bool": "Optional boolean",

View File

@ -105,6 +105,7 @@ class DemoVacuum(VacuumEntity):
"""Representation of a demo vacuum."""
_attr_should_poll = False
_attr_translation_key = "model_s"
def __init__(self, name: str, supported_features: VacuumEntityFeature) -> None:
"""Initialize the vacuum."""
@ -247,6 +248,7 @@ class StateDemoVacuum(StateVacuumEntity):
_attr_should_poll = False
_attr_supported_features = SUPPORT_STATE_SERVICES
_attr_translation_key = "model_s"
def __init__(self, name: str) -> None:
"""Initialize the vacuum."""

View File

@ -269,9 +269,15 @@ def gen_strings_schema(config: Config, integration: Integration) -> vol.Schema:
},
vol.Optional("entity"): {
str: {
str: vol.Schema(
{vol.Optional("state"): {str: cv.string_with_no_html}}
)
str: {
vol.Optional("state_attributes"): {
str: {
vol.Optional("name"): cv.string_with_no_html,
vol.Optional("state"): {str: cv.string_with_no_html},
}
},
vol.Optional("state"): {str: cv.string_with_no_html},
}
}
},
}