mirror of
https://github.com/esphome/esphome.git
synced 2026-10-06 19:06:37 +00:00
Address review: robust regex and comment accuracy
- Fix extract_packed_value regex to handle commas in entity names by matching C++ string literals instead of [^,]+ - Only describe dc/uom/icon in comments when their index is actually non-zero, so comment matches what was packed
This commit is contained in:
@@ -9,7 +9,11 @@ INTERNAL_BIT = 1 << 24
|
||||
|
||||
def extract_packed_value(main_cpp: str, var_name: str) -> int:
|
||||
"""Extract the third (packed) argument from a configure_entity_ call."""
|
||||
pattern = rf"{re.escape(var_name)}->configure_entity_\([^,]+,\s*\w+,\s*(\d+)\)"
|
||||
pattern = (
|
||||
rf"{re.escape(var_name)}->configure_entity_\("
|
||||
r'"(?:\\.|[^"\\])*"'
|
||||
r",\s*\w+,\s*(\d+)\)"
|
||||
)
|
||||
match = re.search(pattern, main_cpp)
|
||||
assert match, f"configure_entity_ call not found for {var_name}"
|
||||
return int(match.group(1))
|
||||
|
||||
Reference in New Issue
Block a user