Skip to content

Commit

Permalink
optional duration
Browse files Browse the repository at this point in the history
  • Loading branch information
tillsteinbach committed Feb 1, 2025
1 parent 2058246 commit 13b2188
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/carconnectivity/command_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ class HonkAndFlashCommand(GenericCommand):
"""
HonkAndFlashCommand is a command class for honking and flashing the lights.
"""
def __init__(self, name: str = 'honk-flash', parent: Optional[GenericObject] = None) -> None:
def __init__(self, name: str = 'honk-flash', parent: Optional[GenericObject] = None, with_duration: bool = False) -> None:
super().__init__(name=name, parent=parent)
self.with_duration: bool = with_duration

@property
def value(self) -> Optional[Union[str, Dict]]:
Expand All @@ -166,13 +167,17 @@ def value(self, new_value: Optional[Union[str, Dict]]) -> None:
parser = ThrowingArgumentParser(prog='', add_help=False, exit_on_error=False)
parser.add_argument('command', help='Command to execute', type=HonkAndFlashCommand.Command,
choices=list(HonkAndFlashCommand.Command))
if self.with_duration:
parser.add_argument('--duration', dest='duration', help='Duration for honking and flashing in seconds', type=int, required=False)
try:
args = parser.parse_args(new_value.split(sep=' '))
except argparse.ArgumentError as e:
raise SetterError(f'Invalid format for HonkAndFlashCommand: {e.message} {parser.format_usage()}') from e

newvalue_dict = {}
newvalue_dict['command'] = args.command
if self.with_duration:
newvalue_dict['duration'] = args.duration
new_value = newvalue_dict
elif isinstance(new_value, dict):
if 'command' in new_value and isinstance(new_value['command'], str):
Expand Down

0 comments on commit 13b2188

Please sign in to comment.