Fix binary sensor translations for carbon_monoxide (#66891)

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
Mick Vleeshouwer 2022-02-21 10:34:38 -08:00 committed by GitHub
parent 9a5eec561a
commit 5af4068583
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 7 deletions

View File

@ -115,9 +115,9 @@
"off": "Not charging", "off": "Not charging",
"on": "Charging" "on": "Charging"
}, },
"co": { "carbon_monoxide": {
"off": "Clear", "off": "[%key:component::binary_sensor::state::gas::off%]",
"on": "Detected" "on": "[%key:component::binary_sensor::state::gas::on%]"
}, },
"cold": { "cold": {
"off": "[%key:component::binary_sensor::state::battery::off%]", "off": "[%key:component::binary_sensor::state::battery::off%]",

View File

@ -59,8 +59,6 @@
"connected": "{entity_name} connected", "connected": "{entity_name} connected",
"gas": "{entity_name} started detecting gas", "gas": "{entity_name} started detecting gas",
"hot": "{entity_name} became hot", "hot": "{entity_name} became hot",
"is_not_tampered": "{entity_name} stopped detecting tampering",
"is_tampered": "{entity_name} started detecting tampering",
"light": "{entity_name} started detecting light", "light": "{entity_name} started detecting light",
"locked": "{entity_name} locked", "locked": "{entity_name} locked",
"moist": "{entity_name} became moist", "moist": "{entity_name} became moist",
@ -134,7 +132,7 @@
"off": "Not charging", "off": "Not charging",
"on": "Charging" "on": "Charging"
}, },
"co": { "carbon_monoxide": {
"off": "Clear", "off": "Clear",
"on": "Detected" "on": "Detected"
}, },

View File

@ -75,7 +75,13 @@ def substitute_reference(value, flattened_translations):
new = value new = value
for key in matches: for key in matches:
if key in flattened_translations: if key in flattened_translations:
new = new.replace(f"[%key:{key}%]", flattened_translations[key]) new = new.replace(
f"[%key:{key}%]",
# New value can also be a substitution reference
substitute_reference(
flattened_translations[key], flattened_translations
),
)
else: else:
print(f"Invalid substitution key '{key}' found in string '{value}'") print(f"Invalid substitution key '{key}' found in string '{value}'")
sys.exit(1) sys.exit(1)