[tcat] feat: add dataset clear command (#10812)

Added 'clear' command to the 'dataset' command tree. This allows to
remove all entries in the 'ThreadDataset' object used by the script to
store the dataset values.

The reason behind this feature is that in the current implementation
of the script, the 'ThreadDataset' object entries are always
initialized by 'initial_dataset' when running the script.

No command allows to clear/remove the particular entry, which makes
this script unable to send an active dataset to the target device
without specific dataset values(custom dataset).

To make this possible, the 'clear' command has been added to the
'dataset' command tree, which removes all entries from the
'ThreadDataset' object and, by using existing commands, sets the
desired entries in the 'ThreadDataset' object from scratch.

This enables the script to send custom active dataset values to the
target device.
This commit is contained in:
Jakub Uliarczyk
2024-10-11 06:48:26 +02:00
committed by GitHub
parent 19b2d6bbc4
commit ed14eb19bd
2 changed files with 15 additions and 0 deletions
@@ -42,6 +42,17 @@ def handle_dataset_entry_command(type: MeshcopTlvType, args, context):
return CommandResultNone()
class DatasetClearCommand(Command):
def get_help_string(self) -> str:
return 'Clear dataset.'
async def execute_default(self, args, context):
ds: ThreadDataset = context['dataset']
ds.clear()
return CommandResultNone()
class DatasetHelpCommand(Command):
def get_help_string(self) -> str:
@@ -194,6 +205,7 @@ class DatasetCommand(Command):
def __init__(self):
self._subcommands = {
'clear': DatasetClearCommand(),
'help': DatasetHelpCommand(),
'hex': PrintDatasetHexCommand(),
'reload': ReloadDatasetCommand(),
+3
View File
@@ -62,3 +62,6 @@ class ThreadDataset:
self.entries[type].set(args)
return
raise KeyError(f'Key {type} not available in the dataset.')
def clear(self):
self.entries.clear()