<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_aldb(self, mem_addr: int, mode: str, group: int, target, data1=0x00, data2=0x00, data3=0x00):
 """Write to the device All-Link Database. Parameters: Required: mode: r - device is a responder of target c - device is a controller of target group: Link group target: Address of the other device Optional: data1: Device dependant data2: Device dependant data3: Device dependant """

        if isinstance(mode, str) and mode.lower() in ['c', 'r']:
            pass
        else:
            _LOGGER.error('Insteon link mode: %s', mode)
            raise ValueError("Mode must be 'c' or 'r'")
        if isinstance(group, int):
            pass
        else:
            raise ValueError("Group must be an integer")

        target_addr = Address(target)

        _LOGGER.debug('calling aldb write_record')
        self._aldb.write_record(mem_addr, mode, group, target_addr,
                                data1, data2, data3)
        self._aldb.add_loaded_callback(self._aldb_loaded_callback)