navd: handle key present with none value (#29025)

old-commit-hash: 60d570349f
This commit is contained in:
Adeeb Shihadeh 2023-07-18 21:19:18 -07:00 committed by GitHub
parent 32d6b9994e
commit 5f8e1afc88
1 changed files with 10 additions and 6 deletions

View File

@ -131,6 +131,10 @@ def maxspeed_to_ms(maxspeed: Dict[str, Union[str, float]]) -> float:
return SPEED_CONVERSIONS[unit] * speed
def field_valid(dat: dict, field: str) -> bool:
return field in dat and dat[field] is not None
def parse_banner_instructions(instruction: Any, banners: Any, distance_to_maneuver: float = 0.0) -> None:
if not len(banners):
return
@ -147,19 +151,19 @@ def parse_banner_instructions(instruction: Any, banners: Any, distance_to_maneuv
# Primary
p = current_banner['primary']
if 'text' in p:
if field_valid(p, 'text'):
instruction.maneuverPrimaryText = p['text']
if 'type' in p:
if field_valid(p, 'type'):
instruction.maneuverType = p['type']
if 'modifier' in p:
if field_valid(p, 'modifier'):
instruction.maneuverModifier = p['modifier']
# Secondary
if 'secondary' in current_banner:
if field_valid(current_banner, 'secondary'):
instruction.maneuverSecondaryText = current_banner['secondary']['text']
# Lane lines
if 'sub' in current_banner:
if field_valid(current_banner, 'sub'):
lanes = []
for component in current_banner['sub']['components']:
if component['type'] != 'lane':
@ -170,7 +174,7 @@ def parse_banner_instructions(instruction: Any, banners: Any, distance_to_maneuv
'directions': [string_to_direction(d) for d in component['directions']],
}
if 'active_direction' in component:
if field_valid(component, 'active_direction'):
lane['activeDirection'] = string_to_direction(component['active_direction'])
lanes.append(lane)