1 # Copyright (c) 2023 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """A module implementing the control panel data structure.
17 from copy import deepcopy
21 """A class representing the control panel.
24 def __init__(self, params: dict, panel: dict) -> None:
25 """Initialisation of the control pannel by default values. If
26 particular values are provided (parameter "panel") they are set
29 :param params: Default values to be set to the control panel. This
30 dictionary also defines the full set of the control panel's
31 parameters and their order.
32 :param panel: Custom values to be set to the control panel.
38 raise ValueError("The params must be defined.")
39 self._panel = deepcopy(params)
42 if key in self._panel:
43 self._panel[key] = panel[key]
46 f"The parameter {key} is not defined in the list of "
51 def panel(self) -> dict:
55 def values(self) -> tuple:
56 """Returns the values from the Control panel as a tuple.
58 :returns: The values from the Control panel.
61 return tuple(self._panel.values())
63 def set(self, kwargs: dict=dict()) -> None:
64 """Set the values of the Control panel.
66 :param kwargs: key - value pairs to be set.
68 :raises KeyError: If the key in kwargs is not present in the Control
71 for key, val in kwargs.items():
72 if key in self._panel:
73 self._panel[key] = val
75 raise KeyError(f"The key {key} is not defined.")
77 def get(self, key: str) -> any:
78 """Returns the value of a key from the Control panel.
80 :param key: The key which value should be returned.
82 :returns: The value of the key.
84 :raises KeyError: If the key in kwargs is not present in the Control
87 return self._panel[key]