Harden unknown vendor value fallbacks
This commit is contained in:
1 parent
b85af10ae1
commit
da49825e2e
7 files changed
+24
-5
No files matched your search
@@ -43,7 +43,11 @@ def _derive_name(state_key: str) -> str:
|
||||
Strips a trailing instance number of 0 (singleton), promotes any other
|
||||
instance number with a space: "door_cooler_open1" → "Door Cooler Open 1".
|
||||
"""
|
||||
name = re.sub(r'(\d+)$', lambda m: f' {m.group()}' if int(m.group()) > 0 else '', state_key)
|
||||
name = re.sub(
|
||||
r'_?(\d+)$',
|
||||
lambda match: f' {match.group(1)}' if int(match.group(1)) > 0 else '',
|
||||
state_key,
|
||||
)
|
||||
return _snake_to_title(name).strip()
|
||||
|
||||
|
||||
|
||||
@@ -129,8 +129,14 @@ def _display(value, translation_key: Optional[str]):
|
||||
"""
|
||||
if not isinstance(value, str):
|
||||
return value
|
||||
if translation_key and (translated := _translation_state(value, translation_key)):
|
||||
return translated
|
||||
if translation_key:
|
||||
if translated := _translation_state(value, translation_key):
|
||||
return translated
|
||||
if translation_key not in TRANSLATED_SELECT_STATES:
|
||||
# The entity name is translated, but this select deliberately has
|
||||
# no static state catalog (for example an unknown course table).
|
||||
# Keep its opaque device value untouched.
|
||||
return value
|
||||
if value.islower():
|
||||
return value.replace('_', ' ').title()
|
||||
return _CAMEL_BOUNDARY_RE.sub(' ', value)
|
||||
|
||||
@@ -488,6 +488,9 @@
|
||||
"filter_progress": {
|
||||
"name": "Filter progress"
|
||||
},
|
||||
"filter_usage": {
|
||||
"name": "Filter usage"
|
||||
},
|
||||
"fine_dust": {
|
||||
"name": "Fine dust"
|
||||
},
|
||||
|
||||
@@ -488,6 +488,9 @@
|
||||
"filter_progress": {
|
||||
"name": "Filter progress"
|
||||
},
|
||||
"filter_usage": {
|
||||
"name": "Filter usage"
|
||||
},
|
||||
"fine_dust": {
|
||||
"name": "Fine dust"
|
||||
},
|
||||
|
||||
@@ -488,6 +488,9 @@
|
||||
"filter_progress": {
|
||||
"name": "Filterverbruik"
|
||||
},
|
||||
"filter_usage": {
|
||||
"name": "Filtergebruik"
|
||||
},
|
||||
"fine_dust": {
|
||||
"name": "Fijnstof"
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user