<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add_device(self, device: Union[DeviceType, str]) -> None: """Add the given |Node| or |Element| object to the actual |Nodes| or |Elements| object. You can pass either a string or a device: Nodes("old_node") Nodes("new_node", "old_node") Method |Devices.add_device| is disabled for immutable |Nodes| and |Elements| objects: Traceback (most recent call last):
 RuntimeError: While trying to add the device `newest_node` to a \ Nodes object, the following error occurred: Adding devices to immutable \ Nodes objects is not allowed. """

        try:
            if self.mutable:
                _device = self.get_contentclass()(device)
                self._name2device[_device.name] = _device
                _id2devices[_device][id(self)] = self
            else:
                raise RuntimeError(
                    f'Adding devices to immutable '
                    f'{objecttools.classname(self)} objects is not allowed.')
        except BaseException:
            objecttools.augment_excmessage(
                f'While trying to add the device `{device}` to a '
                f'{objecttools.classname(self)} object')